1.Docker 是google用go语言开发的一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口
2.组成:docker容器--守护进程 docker容器里面的应用 镜像文件
3.安装docker
https://store.docker.com/editions/community/docker-ce-server-centos
$sudo yum install -y yum-utils device-mapper-persistent-data lvm2
添加仓库:
sudo yum-config-manager--add-repo \https://download.docker.com/linux/centos/docker-ce.repo
[xuxin@weric /]$ sudo yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
设置yum使用高速缓存:sudo yum makecache fast
安装docker-ce
sudo yum install docker-ce
启动docker服务进程:
sudo systemctl start docker
xuxin@xuxin /]$ sudo systemctl start docke
运行一个容器:sudo docker run hello-world
如果没有这个容器会先下载这个容器,其后再运行。
[xuxin@xuxin /]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
o generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
4:Docker的更多命令
1:查看docker的信息
$ sudo docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
2:查看images
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 1815c82652c0 6 days ago 1.84 kB
3:查看容器
[wangjian@weric /]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c9757a01376 hello-world "/hello" 3 minutes ago Exited (0) 3 minutes ago angry_bassi
4:删除容器
$ sudo docker rm 8c98c9
5:删除镜像
$ sudo docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Deleted: sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57
Deleted: sha256:45761469c965421a92a69cc50e92c01e0cfa94fe026cdd1233445ea00e96289a
6:添加一个用户,让当前用户属于docker组-可选的
$ cat /etc/group | grep docker
docker:x:993:
修改当前用户,属性docker组:
$ sudo usermod -a -G docker
$ cat /etc/group | grep docker
docker:x:993:xuxin
4:配置镜像下载加速的地址
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -shttp://57d803f6.m.daocloud.io
5:安装mysql
镜像地址:
https://hub.docker.com/_/mysql/
下载镜像:$ docker pull mysql
下载时: 下载一个:Linux - 在Linux里面安装一个Mysql.
启动这个镜像:docker run
查看正在运行的容器:
$ docker run --name mysqlA -p 3307:3306 -p 2222:22 -d -e MYSQL_ROOT_PASSWORD=1234 mysqlffd3faead829fe7633c92a4e3178135c9d6080463302624a902fdee6f9570e7b
$ docker ps
ONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ffd3faead829 mysql "docker-entrypoint..." 3 seconds ago Up 2 seconds 0.0.0.0:2222->22/tcp, 0.0.0.0:3307->3306/tcp mysqlA
一个docker容器启动成功以后,就是一个Linux启动成功了,里面又安装了一个Mysql:
$ docker exec -it mysqlA bash
root@ffd3faead829:/# ls
停止某个
docker stop id/名称
docker start id/名称