docker
Startup
1 | docker container run hello-world |
first pull the image from the registry
then run this image to become a container
1 | docker image pull alpine |
1 | docker container run alpine ls -l |
a few things happen:
- find the image
- run image ==> container
- run cmd
- close container
1 | docker container run -it alpine /bin/sh |
launch the shell and you can type in the terminal
swarm
in one node: (manager)
1 | docker swarm init --advertise-addr $(hostname -i) |
in other node: (worker) copy & paste
1 | docker swarm join --token <token> <host> |
in the manager node
1 | docker node ls |
create a stack in the manager
1 | docker stack deploy --compose-file=docker-stack.yml voting_stack |
a docker-stack.yml is like
1 | # this file is meant for Docker Swarm stacks only |
![[{3A3E94E1-7C8E-4C55-9E2F-155FDB1904DD}.png]]
container
docker run : 新建并启动
1 | docker run -t -i ubuntu:18.04 /bin/bash |
start a exited container
1 | docker container start |
后台运行:-d
1 | docker run -d ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done" |
在后台后可以通过 container logs 查看标准输出
容器终止:
1 | docker container stop |
或者等所有命令结束自动终止
删除所有终止状态的容器
1 | docker container prune |
Dockerfile
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.