下載yum文件
wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repolinux
vim docker-ce.repo
把裏面的網址替換爲國內docker安裝的網址 (%s@s_content@d_content@)
https://mirrors.tuna.tsinghua.edu.cn/docker-cenginx
安裝:
yum install docker-ceweb
作倉庫加速
mkdir /etc/docker && vim daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}redis
啓動
systemctl start docker.servicedocker
命令:
docker version
docker info
docker --help
docker search nginx json
alpine 用於微小環境使用的版本 (測試使用,通常都不帶調試工具)vim
docker image pull nginx:1.14-alpine 拉取nginx:1.14-alpine鏡像(下載到本地)centos
docker image ls 顯示本地業務鏡像tcp
docker container create Create a new container
start Start one or more stopped containers
stop Stop one or more running container
kill Kill one or more running containers (強行中止)
rm Remove one or more containers
run Run a command in a new container
ls List containers
#docker container run --help
Usage: docker container run [OPTIONS] IMAGE [COMMAND] [ARG... ide
[root@localhost docker]# docker network ls (默認是加入到bridge) --net橋
NETWORK ID NAME DRIVER SCOPE
88ff822f6fb8 bridge bridge local
f9d368813f78 host host local
e89e4a2ba752 none null local
# docker inspect b2 查看容器b2的配置文件
docker container ls -a 查看全部容器
[root@localhost docker]# docker start --help 激活停之狀態的容器
Usage: docker start [OPTIONS] CONTAINER [CONTAINER...]
Start one or more stopped containers
Options:
-a, --attach Attach STDOUT/STDERR and forward signals
--detach-keys string Override the key sequence for detaching a container
-i, --interactive Attach container's STDIN
[root@localhost docker]# docker container start -a -i b2
[root@localhost docker]# docker container rm b2 刪除中止狀態的容器
[root@localhost docker]# docker container run --name web1 -d nginx:1.14-alpine 建立一個nginx容器
docker container ps 查看容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2b467342ac21 nginx:1.14-alpine "nginx -g 'daemon of…" 45 seconds ago Up 44 seconds 80/tcp
[root@localhost docker]# docker container run --name kvstor1 -d redis:4-alpine
[root@localhost docker]# docker container exec -it kvstor1 /bin/sh 進入容器查看業務運行狀況
/data # ps
PID USER TIME COMMAND
1 redis 0:00 redis-server
12 root 0:00 /bin/sh
17 root 0:00 ps
/data # netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
tcp 0 0 :::6379 :::* LISTEN
/data # redis-cli
[root@localhost docker]# docker logs web1 日誌查看 web1