简体   繁体   English

从Dockerfile创建docker-compose文件

[英]create docker-compose file from Dockerfile

I have this simple Dockerfile: 我有这个简单的Dockerfile:

FROM node:boron

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

EXPOSE 8080
CMD [ "npm", "start" ]

I would like to use docker-compose so that I can simply say docker-compose up or docker-compose down . 我想使用docker-compose,这样我可以简单地说docker-compose updocker-compose down

I am struggling to find a simple docker-compose example of how I would use docker-compose , all I can find are examples like this which cover more ground than I need. 我正在努力寻找一个简单的docker-compose示例来说明如何使用docker-compose ,我所能找到的都是像这样的示例,它涵盖了我所需要的更多内容。

How could I create a simple docker-compose file from the above? 我如何从上面创建一个简单的docker-compose文件?

You write following in docker-compose.yml file to run your docker container using compose: 您在docker-compose.yml文件中编写以下代码,以使用compose运行docker-compose.yml容器:

version: '3'

services:
  app:
    build: .
    ports:
      - 8080:8080

Docker compose file is made of multiple services but in your case it is enough to define one service. Docker compose文件由多个服务组成,但是在您的情况下,定义一个服务就足够了。 build option specifies from where to pick up the Dockerfile to build the image and ports will allow port forwarding from the container to you host OS. build选项指定从何处拾取Dockerfile来构建映像,并且ports将允许端口从容器转发到您的主机OS。

To start the service you can use: 要启动该服务,您可以使用:

docker-compose up

And to stop the service: 并停止服务:

docker-compose down

You can find more documentation about the compose file here 您可以在此处找到有关撰写文件的更多文档

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

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