Docker简单使用
1.安装
1 yum install docker #centos 2 apt install docker #ubuntu
2.启动docker
1 sudo systemctl start docker
3.修改国内源
1 vim /etc/docker/daemon.json 2 { 3 "registry-mirrors": ["https://registry.docker-cn.com"] 4 }
改完后重启docker
1 systemctl restart docker
4.查找docker镜像
#以httpd为例
docker search httpd
结果如下
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/httpd The Apache HTTP Server Project 1796 [OK] docker.io docker.io/hypriot/rpi-busybox-httpd Raspberry Pi compatible Docker Image with ... 41 docker.io docker.io/centos/httpd 18 [OK] docker.io docker.io/centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or b... 13 docker.io docker.io/armhf/httpd The Apache HTTP Server Project 8 docker.io docker.io/macadmins/netboot-httpd use in combination with bruienne/bsdpy 6 [OK] docker.io docker.io/lolhens/httpd Apache httpd 2 Server 2 [OK] docker.io docker.io/salim1983hoop/httpd24 Dockerfile running apache config 2 [OK] docker.io docker.io/epflidevelop/os-wp-httpd WP httpd 1 [OK] docker.io docker.io/fboaventura/dckr-httpd Small footprint http server to use with ot... 1 [OK] docker.io docker.io/lead4good/httpd-fpm httpd server which connects via fcgi proxy... 1 [OK] docker.io docker.io/rgielen/httpd-image-simple Docker image for simple Apache httpd based... 1 [OK] docker.io docker.io/tplatform/aws-linux-httpd24-php70 aws-linux-httpd24-php70 1 [OK] docker.io docker.io/tplatform/aws-linux-httpd24-php71-fpm aws-linux-httpd24-php71-fpm 1 [OK] docker.io docker.io/amd64/httpd The Apache HTTP Server Project 0 docker.io docker.io/buzzardev/httpd Based on the official httpd image 0 [OK] docker.io docker.io/cilium/demo-httpd 0 docker.io docker.io/dockerpinata/httpd 0 docker.io docker.io/interlutions/httpd httpd docker image with debian-based confi... 0 [OK] docker.io docker.io/manageiq/httpd Container with httpd, built on CentOS for ... 0 [OK] docker.io docker.io/manasip/httpd 0 docker.io docker.io/ppc64le/httpd The Apache HTTP Server Project 0 docker.io docker.io/publici/httpd httpd:latest 0 [OK] docker.io docker.io/tplatform/aws-linux-httpd24-php71 aws-linux-httpd24-php71 0 [OK] docker.io docker.io/trollin/httpd
5.拉取镜像
#以httpd为例
docker pull docker.io/centos/httpd
也可简化为
docker pull centos/httpd
但是不能是
docker pull httpd
httpd和centos/httpd是两个镜像
6.查看镜像
docker images
7.运行容器
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
8.容器改名
容器名称可以在run的时候使用参数--name来设定
docker rename old_container_name new_container_name
9.启动/重启/停止容器
docker start/restart/stop container_id/container_name
10.查看容器
查看正在使用的容器
docker ps
查看所有容器
docker ps -a
11.删除容器
docker rm container_id/container_name
如果有正在运行的容器,可以加上-f强制删除
docker rm container_id/container_name
12.修改docker的端口映射
查看需要修改的容器,记住container id
docker ps -a
停止容器
docker stop xxx
修改容器的端口映射配置文件
vim /var/lib/docker/containers/{container_id}/hostconfig.json "PortBindings": { "80/tcp": [ { "HostIp": "", "HostPort": "8080"//宿主机端口 } ] },
重启docker服务
service docker restart
启动容器
docker start xxx
停止容器
docker stop xxx