2020-05-26 Docker使用

Win上安裝docker使用

1、安裝mysql鏡像

# 拉取docker鏡像,:[version]指定版本,不加則為latest
docker pull mysql:[version]
拉取mysql鏡像

2、制作docker容器

#啟動(dòng)mysql
docker run --name myDockerMysql -e MYSQL_ROOT_PASSWORD=521379 -dp 3307:3306 mysql
啟動(dòng)mysql

2、安裝centos

# 拉取docker鏡像,:[version]指定版本,不加則為latest
docker pull centos:[version]
centos
#啟動(dòng)
docker run --name mycentos -dp 8888:8888 centos
啟動(dòng)

3、docker命令

#查看所有鏡像
docker images
#查看所有容器
docker ps -a
#docker修改centos的root密碼
rpm -e cracklib-dicts --nodeps
yum install cracklib-dicts
passwd root

docker鏡像加速地址

批量操作

1、批量停止所有容器
docker stop docker ps -a -q

2、批量刪除所有容器
docker rm docker ps -a -q

3、批量刪除所有鏡像
docker rmi docker images -q

4、按條件刪除鏡像(沒(méi)有打標(biāo)簽)

1.>docker rmi docker images -q | awk '/^<none>/ { print $3 }' //鏡像名包含關(guān)鍵字

2.>docker rmi --force docker images | grep doss-api | awk '{print $3}' //其中doss-api為關(guān)鍵字

docker save -o ./xxx.tar [image-name]
docker load -i xxx.tar

https://linuxize.com/post/how-to-disable-selinux-on-centos-7/

docker離線安裝

#下載docker安裝包
wget https://download.docker.com/linux/static/stable/x86_64/docker-version
#解壓
tar -xvf docker-19.03.9.tgz
#將解壓出來(lái)的docker文件復(fù)制到 /usr/bin/ 目錄下
cp docker/* /usr/bin/
#進(jìn)入/etc/systemd/system/目錄,并創(chuàng)建docker.service文件
cd /etc/systemd/system/
touch docker.service
#docker.service文件,將以下內(nèi)容復(fù)制
vi docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd 
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
#給docker.service文件添加執(zhí)行權(quán)限
chmod 777 /etc/systemd/system/docker.service
#重新加載配置文件(每次有修改docker.service文件時(shí)都要重新加載下)
systemctl daemon-reload 
#啟動(dòng)(為了初始化)
systemctl start docker
#開(kāi)機(jī)自啟
systemctl enable docker.service

配置docker網(wǎng)段

在/etc/docker/daemon.json添加
{
"bip":""
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容