1.在linux下面安装docker容器
yum -y install docker
systemctl start docker
systemctl status docker
2.拉取docker镜像
docker pull ubuntu: 16.04
或者从仓库中下载容器
docker pull registry.hub.docker.com/ubuntu:latest
3.查看docker信息
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu 16.04 dfeff22e96ae 6 days ago 131 MB
docker.io/ubuntu latest 9140108b62dc 4 weeks ago 72.9 MB
docker.io/microsoft/mssql-server-linux latest 314918ddaedf 22 months ago 1.35 GB
查看镜像的详细信息
[root@localhost ~]# docker inspect dfeff22e96ae
[
{
"Id": "sha256:dfeff22e96ae3ad07737cd170c0af288948ce426dafdccad5640f991087adde4",
"RepoTags": [
"docker.io/ubuntu:16.04"
],
"RepoDigests": [
"docker.io/ubuntu@sha256:bb69f1a2b6c840b01eeffef07386e95a74ecac8bfa52d35c32fb526c85e00678"
],
"Parent": "",
"Comment": "",
"Created": "2020-10-23T17:33:10.739469082Z",
"Container": "bad92e996031e456b82ad9b96aa426882093d723bc45c9d7f31e03bcc010f81b",
"ContainerConfig": {
"Hostname": "bad92e996031",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"ArgsEscaped": true,
"Image": "sha256:a6f2c57b656e1ca8b66f9d7eb8ea30844b5b4f0f7c4af787255fc4f8eb90df89",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "18.09.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:a6f2c57b656e1ca8b66f9d7eb8ea30844b5b4f0f7c4af787255fc4f8eb90df89",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 130563805,
"VirtualSize": 130563805,
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/3002e3fb69a2795e214c10d814612b8af627d0973d8d08e16b6d23647b65834c/diff:/var/lib/docker/overlay2/229fb995e7c15b99d1e217b837917745fe0175e0f110a8e683744032c8dd38e6/diff:/var/lib/docker/overlay2/99c1df897286b05578055b638d7348b794ee4686f12dd8ce54c417b5b2b726bb/diff",
"MergedDir": "/var/lib/docker/overlay2/dc8e5876992205ab379f8767786d59c54614c8e5016c93ca064edf345d3fafd8/merged",
"UpperDir": "/var/lib/docker/overlay2/dc8e5876992205ab379f8767786d59c54614c8e5016c93ca064edf345d3fafd8/diff",
"WorkDir": "/var/lib/docker/overlay2/dc8e5876992205ab379f8767786d59c54614c8e5016c93ca064edf345d3fafd8/work"
}
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:61727f5e6796a2d90ed9d0dc385a3c1a3b6ded69a5bc4709542a4f47e877ba03",
"sha256:eff16de3ff6467c1bc2afd0bae39c7ee86725e42f6a3cfb691c7688767c89ed9",
"sha256:62fdddf6a67c88f7d7f9f19c0ebd6651be77b93ce6d99ca67018df7714e775e3",
"sha256:9edaa71ce2334d676da80820de71477b34b1e04078dfe0c2ca735f5d951a4c70"
]
}
}
]
4.搜寻镜像
[root@localhost ~]# docker search mysql
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/mysql MySQL is a widely used, open-source relati... 10115 [OK]
docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 3715 [OK]
docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 739 [OK]
docker.io docker.io/percona Percona Server is a fork of the MySQL rela... 511 [OK]
docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 84
docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 77
docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 60 [OK]
docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 45 [OK]
docker.io docker.io/deitch/mysql-backup REPLACED! Please use http://hub.docker.com... 41 [OK]
docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 35
docker.io docker.io/databack/mysql-backup Back up mysql databases to... anywhere! 31
docker.io docker.io/prom/mysqld-exporter 31 [OK]
docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 29 [OK]
docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 26
docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 19
docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 17
docker.io docker.io/arey/mysql-client Run a MySQL client from a docker container 15 [OK]
docker.io docker.io/fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron t... 10 [OK]
docker.io docker.io/yloeffler/mysql-backup This image runs mysqldump to backup data u... 7 [OK]
docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6
docker.io docker.io/devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offi... 3
docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
docker.io docker.io/jelastic/mysql An image of the MySQL database server main... 1
docker.io docker.io/widdpim/mysql-client Dockerized MySQL Client (5.7) including Cu... 1 [OK]
5.删除镜像
根据标签和仓库删除
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu 16.04 dfeff22e96ae 6 days ago 131 MB
docker.io/ubuntu latest 9140108b62dc 4 weeks ago 72.9 MB
docker.io/microsoft/mssql-server-linux latest 314918ddaedf 22 months ago 1.35 GB
[root@localhost ~]# docker rmi docker.io/ubuntu:latest
Untagged: docker.io/ubuntu:latest
Untagged: docker.io/ubuntu@sha256:bc2f7250f69267c9c6b66d7b6a81a54d3878bb85f1ebb5f951c896d13e6ba537
Deleted: sha256:9140108b62dc87d9b278bb0d4fd6a3e44c2959646eb966b86531306faa81b09b
Deleted: sha256:69ea0ba6086b4837bc259353a9dec7e6f7bcc9b8297b0f722387a114697e5691
Deleted: sha256:923b52e8276c042a8602849149a284ae77cccf4c688cc4284bf01ec9669a6e6c
Deleted: sha256:d42a4fdf4b2ae8662ff2ca1b695eae571c652a62973c1beb81a296a4f4263d92
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu 16.04 dfeff22e96ae 6 days ago 131 MB
docker.io/microsoft/mssql-server-linux latest 314918ddaedf 22 months ago 1.35 G
根据id删除
[root@localhost ~]# docker rmi 314918ddaedf
Untagged: docker.io/microsoft/mssql-server-linux:latest
Untagged: docker.io/microsoft/mssql-server-linux@sha256:9b700672670bb3db4b212e8aef841ca79eb2fce7d5975a5ce35b7129a9b90ec0
Deleted: sha256:314918ddaedfedc0345d3191546d800bd7f28bae180541c9b8b45776d322c8c2
Deleted: sha256:7137e6b5089a5be6f4158ea854662c1b698e0193cd5b45c0ffa3752576f7b905
Deleted: sha256:40bdc5bf2f299e4632d2aa0c5b708f2ce4abf5b2b90b51816e51c368ca90a5d1
Deleted: sha256:a688a4e16289df1bd4d247ea5cb7e1d0b47008cddee2c64b7ab302a9d1524034
Deleted: sha256:6f97564562534bd80e4f7293f8f39752525c02bd4a13754ba76e9c68d2c6e6ea
Deleted: sha256:ef572e1ba2ecca900f0ec3db00e997de12dd380ce3e360b5813fd75920232359
Deleted: sha256:98fc4d5421178c7be7d5718d2d44abba8053dc5c712e51658fe5b872675b4f7a
Deleted: sha256:7b2cc05dfd889e28234f8831c80ac20cf299d5bbebbbac013f8f7d2b7abc0d65
Deleted: sha256:6b0187d1cdff63eb5966ac72bf4ccd96150586c1409eb858bb98783f02018ee7
Deleted: sha256:644879075e24394efef8a7dddefbc133aad42002df6223cacf98bd1e3d5ddde2
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu 16.04 dfeff22e96ae 6 days ago 131 MB
6.创建镜像
1.创建容器
[root@localhost ~]# docker run -ti docker.io/ubuntu:16.04 /bin/bash
root@3342aac99c76:/# touch test
root@3342aac99c76:/# exit
exit
2.根据容器创建镜像
[root@localhost ~]# docker commit -m "add a new file" -a "Docker Newbee" 3342aac99c76 test
sha256:75a83d0ffb4968213a6df436762fb4c1ddd1a6129292fff6af4cc6ac086638af
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test latest 75a83d0ffb49 5 seconds ago 131 MB
docker.io/ubuntu 16.04 dfeff22e96ae 6 days ago 131 MB
或者采用如下命令
[root@localhost ~]# docker commit 3342aac99c76 test2
3.基于本地模板导入
cat ubuntu-14.04-x86_64-minimal.tar.gz | docker import - ubuntu:14.04
7.存出和载入镜像
存出镜像
[root@localhost ~]# docker save -o ubuntu_14.04.tar docker.io/ubuntu
[root@localhost ~]# ls
anaconda-ks.cfg ubuntu_14.04.tar
载入镜像
[root@localhost ~]# docker load --input ubuntu_14.04.tar
Loaded image: docker.io/ubuntu:16.04
8.上传镜像
[root@localhost ~]# docker tag docker.io/ubuntu:16.04 1111111/test:latest
[root@localhost ~]# docker push 1111111/test:latest
The push refers to a repository [docker.io/user/test]
9edaa71ce233: Preparing
62fdddf6a67c: Preparing
eff16de3ff64: Preparing
61727f5e6796: Preparing
denied: requested access to the resource is denied
出错,此时需要登录私人账号,可以在docker的官网上申请账号,其地址为https://hub.docker.com/
[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 1773570500
Password:
再次上传镜像
[root@localhost ~]# docker tag docker.io/ubuntu:16.04 1111111/mylocal:latest
[root@localhost ~]# docker push 11111111/mylocal:latest
The push refers to a repository [docker.io/1773570500/mylocal]
9edaa71ce233: Pushed
62fdddf6a67c: Pushed
eff16de3ff64: Pushed
61727f5e6796: Pushed
latest: digest: sha256:92b36e8a01defa1ed16c40d581f3b0482d4eaedbc63bfe074a7dd3bf100ba020 size: 1150
上传成功,可以在仓库中看到该容器。