docker_practice/image/dockerfile/cmd.md

50 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### CMD
`CMD` `RUN`
* `shell` `CMD <命令>`
* `exec` `CMD ["可执行文件", "参数1", "参数2"...]`
* `CMD ["参数1", "参数2"...]` `ENTRYPOINT` `CMD`
Docker `CMD`
`ubuntu` `CMD` `/bin/bash` `docker run -it ubuntu` `bash` `docker run -it ubuntu cat /etc/os-release` `cat /etc/os-release` `/bin/bash`
使 `exec` JSON 使 `"`使
使 `shell` `sh -c`
```docker
CMD echo $HOME
```
```docker
CMD [ "sh", "-c", "echo $HOME" ]
```
使 shell
`CMD`
Docker `systemd`
`CMD`
```docker
CMD service nginx start
```
退使 `systemctl`
退退西
使 `service nginx start` upstart `nginx` `CMD service nginx start` `CMD [ "sh", "-c", "service nginx start"]` `sh` `service nginx start` `sh` `sh` 退退
`nginx`
```docker
CMD ["nginx", "-g", "daemon off;"]
```