简体   繁体   English

如何编写 Docker 文件并为 Rails 服务器编写

[英]How to write Docker file and compose for rails server

i'm newbie to Docker.我是 Docker 的新手。 I have a web app which is written in react js.我有一个用 react js 编写的 web 应用程序。 It contains rails(sqlite3) server to store the data.它包含用于存储数据的 rails(sqlite3) 服务器。 I have file structure as follows:我的文件结构如下:

  Project:
    1.Front end: dockerfile1, .dockerignore1
    2.Back end: docker file2 , .dockerignore2
    3.Dockercompose.yml

dockerfile1:码头文件1:

 # Stage 1
 FROM node:8 as react-build
 WORKDIR /app
 COPY . ./
 RUN yarn
 RUN yarn build

# Stage 2 - the production environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=react-build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

.dockerignore1 .dockerignore1

.git
 node_modules
 build

Then I have created the container1: $ docker build.然后我创建了 container1: $ docker build。 -t container1 When i run '$ docker run -p 8000:80 container1' & when i give ' http://localhost:8000 ' on browser, it displays front end page. -t container1 当我在浏览器上运行“$ docker run -p 8000:80 container1”&当我给出“ http://localhost:8000 ”时,它会显示前端页面。

I don't know how to write the dockerfile2 for rails server which has sqlite3 database.我不知道如何为具有 sqlite3 数据库的 rails 服务器编写 dockerfile2。 Then I should write docker compose file.Someone please help me to write docker compose file for communicate between web app and rails server.然后我应该写 docker 撰写文件。有人请帮我写 docker 撰写文件,以便在 web 应用程序和 rails 服务器之间进行通信。 Thanks in advance.提前致谢。

follow these instruction by docker:按照 docker 的这些说明进行操作:

https://docs.docker.com/compose/rails/ https://docs.docker.com/compose/rails/

also to know structure check below link:还要了解以下链接的结构检查:

https://github.com/adaam2/docker-rails-react-starter https://github.com/adaam2/docker-rails-react-starter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM