The Tips About Dockerfile
January 18, 2025 · 3 min read · Page View:
Normally, we often write a Dockerfile
in the current directory.
- The
Dockerfile
is a configuration file that describes how to build the image. You can refer to the official documentation for more details. - If you list more than one
CMD
, only the last one takes effect. So if you have multiple commands to run, you better write them in a script file. - Docker is not the VMware, there is no
systemd
in the container. Its startup program is the container application process. The container exists for the main process. Once the main process exits, the container loses its meaning of existence and thus exits. So when you execute multiple commands and if they are blocking, you better write the previous commands in nohup and the last command in the blocking command. (never use the command such asCMD service nginx start
, the CMD only will execute asCMD [ "sh", "-c", "service nginx start"]
, when the sh is executed, the container will exit, the correct way is run it directlyCMD ["nginx", "-g", "daemon off;"]
)