将Docker create命令转换为docker-compose文件

huangapple go评论56阅读模式
英文:

Converting Docker create command into docker-compose file

问题

I need to convert this to a DockerFile, and have no idea where to start, could someone help me out please?

FROM <base_image>

# Set environment variables
ENV PUID=1001
ENV PGID=1001

# Create directories
RUN mkdir -p /config /mnt/<My_Vol_1> /mnt/<My_Vol_2> /mnt/<My_Vol_3> /downloads

# Copy files
COPY <dockerInstance> /config
COPY <dockerInstance> /downloads

# Expose ports
EXPOSE <PORT>

CMD ["your_command"]

Please replace <base_image>, <PORT>, <dockerInstance>, and <My_Vol_X> with the appropriate values for your setup.

英文:

I need to convert this to a DockerFile, and have no idea where to start, could someone help me out please?

docker create --name=&lt;NAME&gt; --restart=always -p &lt;PORT&gt;:&lt;PORT&gt; -e PUID=1001 -e PGID=1001 -v /dev/rtc:/dev/rtc:ro -v /var/lib/&lt;dockerInstance&gt;:/config -v /mnt/&lt;My_Vol_1&gt;:/mnt/&lt;My_Vol_1&gt; -v /mnt/&lt;My_Vol_2&gt;:/mnt/&lt;My_Vol_2&gt; -v /mnt/&lt;My_Vol_3&gt;:/mnt/&lt;My_Vol_1&gt; -v /mnt/&lt;My_Vol_4&gt;:/downloads &lt;dockerInstance&gt;

答案1

得分: 1

根据您提供的内容,以下是翻译好的部分:

你所提供的内容,你需要的不是一个Dockerfile,而是一个docker-compose文件。你在这里的命令创建了一个容器,这个容器需要一个镜像才能运行。

一个Dockerfile允许你创建一个包含一组指令的镜像。
一个Docker compose文件允许你以多个参数运行这个镜像(或多个镜像),比如要暴露的端口。

在你的情况下,可以是这样的:

version: "3.9"
services:
  <NAME>:
    image: <IMAGE>
    container_name: <NAME>
    ports:
      - "<PORT>:<PORT>"

之后你可以使用 docker compose up 来运行你的容器。

这并不是完整的转换你的命令的文件,但是这是一个很好的开始。
关于Docker Compose的文档请参考这里。

英文:

With what you gave, what you need is not a Dockerfile but a docker-compose file. Your command here creates a container which needs an image to be able to run.

A Dockerfile allows you to creates an image that contains a set of instructions.
A Docker compose file allows you to run this image (or multiple images) with multiple parameters like the ports to expose.

In your case, it could be :

version: &quot;3.9&quot; 
services:
  &lt;NAME&gt;:
    image: &lt;IMAGE&gt;
    container_name: &lt;NAME&gt;
    ports:
      - &quot;&lt;PORT&gt;:&lt;PORT&gt;&quot;

You can use docker compose up after that to run your container.

It's not the complete file to convert your command but it's a good way to start.
See here for the documentation about the docker compose.

huangapple
  • 本文由 发表于 2023年4月13日 17:39:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定