如果你从未安装和使用过Docker ,请参考 Docker教程https://www.runoob.com/docker/centos-docker-install.html
docker的安装:
使用国内 daocloud 一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
sudo yum-config-manager \
--add-repo \
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
安装最新版本的 Docker Engine-Community 和 containerd,或者转到下一步安装特定版本:
sudo yum install docker-ce docker-ce-cli containerd.io
启动docker
sudo systemctl start docker
##查看正在运行的容器 docker ps
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4178c9ff8b8d mysql "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-test
34394b7afa90 elgalu/selenium:latest "entry.sh" 31 minutes ago Up 31 minutes 40001/tcp, 50001/tcp zalenium_6utDHW
4ae71dc49461 elgalu/selenium:latest "entry.sh" 31 minutes ago Up 31 minutes 40000/tcp, 50000/tcp zalenium_WOdoTN
254ff45fe150 dosel/zalenium "entry.sh start --ma…" 31 minutes ago Up 31 minutes 0.0.0.0:4444->4444/tcp, :::4444->4444/tcp, 4445/tcp zalenium
进入docker容器
[root@dongxun ~]# docker exec -it 4178c9ff8b8d /bin/bash
拉去mysql ,docker镜像
docker pull mysql:latest
启动mysql docker容器
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
进入容器:
docker exec -it 4178c9ff8b8d /bin/bash
链接mysql:
mysql -uroot -p123456
配置允许链接:
alter user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
退出mysql
exit;
退出容器:
exit
docker 容器安装python3.9:
运行镜像:
docker run -itd python:3.9 bash
docker ps
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ddd0d65d5c6 python:3.9 "bash" 10 seconds ago Up 9 seconds awesome_bhaskara
4178c9ff8b8d mysql "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-test
34394b7afa90 elgalu/selenium:latest "entry.sh" 2 hours ago Up 2 hours 40001/tcp, 50001/tcp zalenium_6utDHW
4ae71dc49461 elgalu/selenium:latest "entry.sh" 2 hours ago Up 2 hours 40000/tcp, 50000/tcp zalenium_WOdoTN
254ff45fe150 dosel/zalenium "entry.sh start --ma…" 2 hours ago Up 2 hours 0.0.0.0:4444->4444/tcp, :::4444->4444/tcp, 4445/tcp zalenium
进入容器:
docker exec -it 6a55 bash
python
Python 3.9.7 (default, Sep 3 2021, 20:10:26)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@8ddd0d65d5c6:/# pip list
1、$ sudo docker pull elgalu/selenium
注:这里拉取的是非官方的docker-selenium镜像。
拉取zalenium镜像。
2、$ sudo docker pull dosel/zalenium
速度太慢,可以使用国内镜像:
https://www.docker-cn.com/registry-mirror
查看镜像:
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elgalu/selenium latest 9d39de56e57b 3 days ago 1.4GB
dosel/zalenium latest e5a39a962b2c 8 days ago 746MB
### 运行
docker run --rm -ti --name zalenium -p 4444:4444 \
-e PULL_SELENIUM_IMAGE=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/videos:/home/seluser/videos \
--privileged dosel/zalenium start --maxDockerSeleniumContainers 5 --timeZone "Asia/Shanghai"