CENTOS7下開(kāi)啟Docker,CenterOS7安裝docker要求內(nèi)核版本在3.10以上(uname -r)
yum install docker
啟動(dòng)docker
systemctl start docker
版本查看
docker version
狀態(tài)查看 systemctl status docker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since 四 2020-10-29 10:44:33 CST; 8s ago Docs: http://docs.docker.com Main PID: 6096 (dockerd-current) CGroup: /system.slice/docker.service ├─6096 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdrive └─6107 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir 10月 29 10:44:32 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:32.133897123+08:00" level=info msg="libcontainerd: new containerd process, pid: 6107" 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.511531824+08:00" level=info msg="Graph migration to content-addressability took 0.00 seco 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.514168291+08:00" level=info msg="Loading containers: start." 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.532101146+08:00" level=info msg="Firewalld running: true" 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.747994444+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.865758833+08:00" level=info msg="Loading containers: done." 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.929515913+08:00" level=info msg="Daemon has completed initialization" 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.929568648+08:00" level=info msg="Docker daemon" commit="64e9980/1.13.1" graphdriver=overl 10月 29 10:44:33 vip1.92k.xin dockerd-current[6096]: time="2020-10-29T10:44:33.953292472+08:00" level=info msg="API listen on /var/run/docker.sock" 10月 29 10:44:33 vip1.92k.xin systemd[1]: Started Docker Application Container Engine. |
docker 國(guó)內(nèi)加速,這里其實(shí)改變的就是 倉(cāng)庫(kù) 的位置。
編輯 /etc/docker/deamon.json,然后重啟 docker,內(nèi)容如下:
1 2 3 |
{ "registry-mirrors": ["http://hub-mirror.c.163.com", "https://registry.docker-cn.com"] } |
下面我們來(lái)用docker來(lái)啟用一個(gè)nginx
首先我們需要查找nginx的鏡像(從倉(cāng)庫(kù)里面查找鏡像) docker search nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/nginx Official build of Nginx. 13930 [OK] docker.io docker.io/jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1901 [OK] docker.io docker.io/richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 791 [OK] docker.io docker.io/linuxserver/nginx An Nginx container, brought to you by Linu... 128 docker.io docker.io/jc21/nginx-proxy-manager Docker container for managing Nginx proxy ... 103 docker.io docker.io/tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rt... 99 [OK] docker.io docker.io/bitnami/nginx Bitnami nginx Docker Image 90 [OK] docker.io docker.io/alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from s... 78 [OK] docker.io docker.io/jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 64 [OK] docker.io docker.io/nginxdemos/hello NGINX webserver that serves a simple page ... 62 [OK] docker.io docker.io/nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 43 docker.io docker.io/privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & ... 39 [OK] docker.io docker.io/nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 19 docker.io docker.io/schmunk42/nginx-redirect A very simple container to redirect HTTP t... 19 [OK] docker.io docker.io/centos/nginx-112-centos7 Platform for running nginx 1.12 or buildin... 15 docker.io docker.io/nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 15 docker.io docker.io/centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 13 docker.io docker.io/raulr/nginx-wordpress Nginx front-end for the official wordpress... 13 [OK] docker.io docker.io/staticfloat/nginx-certbot Opinionated setup for automatic TLS certs ... 13 [OK] docker.io docker.io/bitwarden/nginx The Bitwarden nginx web server acting as a... 7 docker.io docker.io/mailu/nginx Mailu nginx frontend 7 [OK] docker.io docker.io/sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats... 7 [OK] docker.io docker.io/bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Con... 6 [OK] docker.io docker.io/ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK] docker.io docker.io/wodby/nginx Generic nginx 1 [OK] |
僅僅為了測(cè)試,我們選擇官方鏡像(docker.io/nginx),下面我們拉取鏡像 docker pull docker.io/nginx
1 2 3 4 5 6 7 8 9 10 |
Using default tag: latest Trying to pull repository docker.io/library/nginx ... latest: Pulling from docker.io/library/nginx bb79b6b2107f: Pull complete 111447d5894d: Pull complete a95689b8e6cb: Pull complete 1a0022e444c2: Pull complete 32b7488a3833: Pull complete Digest: sha256:ed7f815851b5299f616220a63edac69a4cc200e7f536a56e421988da82e44ed8 Status: Downloaded newer image for docker.io/nginx:latest |
查看本地鏡像 docker images -a
1 2 |
REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx latest f35646e83998 2 weeks ago 133 MB |
啟用docker 下面的nginx,為了方便看效果,我們需要停止一下外面的nginx(/web/nginx/sbin/nginx -s stop)。
docker run –name nginx-test -p 80:80 -d nginx
1ac537ed852f725cfe36976f1476267a41885b345e8d5d31411f7abaf30bcc64
啟動(dòng)成功后,系統(tǒng)會(huì)給出容器ID。
-d 啟用后臺(tái)進(jìn)程。 -p 做了端口映射。 -name 作為容器別名。
查看進(jìn)程:docker ps -a
1 2 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1ac537ed852f nginx "/docker-entrypoin..." 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp nginx-test |
我們可以看到 container ID 為后端的容器ID前一段。 NAMES為我們起的容器別名,PORTS給出了端口映射。
停止進(jìn)程: docker stop nginx-test
停止后,我們用docker ps -a 查看
1 2 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1ac537ed852f nginx "/docker-entrypoin..." 4 minutes ago Exited (0) 14 seconds ago nginx-test |
status狀態(tài)發(fā)生了改變,由原來(lái)的UP狀態(tài)改成了 Exited(0)。
我們重新運(yùn)行 docker run –name nginx-test -p 80:80 -d nginx
1 2 |
/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/nginx-test" is already in use by container 1ac537ed852f725cfe36976f1476267a41885b345e8d5d31411f7abaf30bcc64. You have to remove (or rename) that container to be able to reuse that name.. See '/usr/bin/docker-current run --help'. |
系統(tǒng)告訴我們,需要?jiǎng)h除,或者改名 nignx-test。 docker rm nginx-test
我們可以用 docker start [容器ID|容器別名] 啟動(dòng)。
我們重新跑一下nginx,我們需要看下外面的世界。
好了,docker的基本體驗(yàn)完畢,我們要清理一下咯。
docker stop nginx-test //停止我們的nginx-test 容器
docker rm nginx-test //刪除我們的nginx-test 容器
docker rmi nginx -f //刪除我們之前下載的nginx 鏡像