gpt4 book ai didi

docker-compose 镜像导出和导入

转载 作者:行者123 更新时间:2023-12-01 21:54:34 33 4
gpt4 key购买 nike

我有一个 nginx 的 dockerfile。

FROM ubuntu

# File Author / Maintainer
MAINTAINER Maintaner Name

# Install Nginx

# Add application repository URL to the default sources
RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list

# Update the repository
RUN apt-get update

# Install necessary tools
RUN apt-get install -y nano wget dialog net-tools

# Download and Install Nginx
RUN apt-get install -y nginx

# Remove the default Nginx configuration file
RUN rm -v /etc/nginx/nginx.conf

# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/

# Append "daemon off;" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose ports
EXPOSE 80

# Set the default command to execute
# when creating a new container
CMD service nginx start

我有一个 docker-compose.yml 文件。

web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
links:
- redis
redis:
image: redis

运行后

docker-compose up

它从名为“web”的 dockerfile 创建镜像并下载 redis 镜像。它还创建了名为“web_web1”的图像的组合,当我检查

的输出时

docker ps

nginx 和 redis 服务都在运行。我的问题是,如果我将新创建的镜像提交到另一个镜像并导出容器并导入到另一个环境,在执行 docker run 命令期间,它会同时启动 nginx 和 redis 服务吗?

最佳答案

My question is if i commit the newly created image to another image and export the container and import to another environment, during execution of docker run command,will it start both the nginx and redis service?

您所需要的只是更改在 docker-compose.yml 中声明的容器名称和端口映射,并且您可以根据需要启动这些镜像的任意数量的实例(无需导出/导入)

关于docker-compose 镜像导出和导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35078916/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com