title |
---|
Docker |
-
DESKTOP
平台 x86_64 Docker Desktop for Mac (macOS) 支持 Docker Desktop for Windows (Microsoft Windows 10) 支持 -
SERVER
sudo apt update sudo apt install docker.io
sudo apt install docker-compose
mkdir tesdocker & cd tesdocker
git clone https://github.com/docker/getting-started.git
cd getting-started
docker build -t docker101tutorial .
docker run -d -p 80:80 --name docker-tutorial docker101tutorial
docker tag docker101tutorial androllen/docker101tutorial
docker push androllen/docker101tutorial
sudo rsync -av [email protected]:/home/lord/code /home/lord
# 去 源服务器 找到 docker 镜像
docker images
docker save -o spring /home/lord/docker/spring.tar
# or
docker save myimage:latest | gzip > myimage_latest.tar.gz
#!/bin/bash
RESLIST=("nginx:latest" "postgres:latest")
echo ${RESLIST[@]}
SAVE_DIR=`pwd`/bak
mkdir $SAVE_DIR
echo "$SAVE_DIR"
for skill in ${RESLIST[@]}; do
echo "=======${skill}"
docker save $skill | gzip > $SAVE_DIR/$skill.tar.gz
done
chown "$USER":"$USER" -R $SAVE_DIR
echo "save over"
#!/bin/bash
RESLIST=("redis:5.0.3" "mongo:latest" "mysql:5.7")
SAVE_DIR=`pwd`/bak
for name in ${RESLIST[@]}; do
echo $name
docker save $name -o $SAVE_DIR/$name.tar
done
chown "dogs":"dogs" -R $SAVE_DIR
# 把上面的内容 保存 save.sh
sudo vim load.sh
# 在 Ubuntu 任意目录下执行脚本
sudo bash save.sh
# 加载保存的文件到 image
docker load -i spring.tar
# 后台模式启动一个容器
docker run -d spring:latest
#!/bin/bash
list=`ls -l | awk '{print $9}'`
for name in ${list[@]}; do
echo $name
docker load -i $name
done
echo "load over"
# 去目标服务器 加载 docker 镜像,使用load.sh
# 把上面的内容 保存 load.sh
sudo vim load.sh
# 在`Ubuntu` 镜像目录下执行 load.sh 脚本
sudo bash load.sh
# cd to project dir
sudo docker-compose up -d
sudo docker ps
当安装完成测试结束的时候,我们需要在重启进行自启,这个时候,我们就要:
- docker 开机自启动
sudo systemctl enable docker
- 启动 docker
sudo service docker start
- docker-compose 开机自启动
用docker-compose启动,yml文件中 镜像 加入restart: always这个参数
https://docs.docker.com/compose/compose-file/#build
https://github.com/docker/labs/tree/master/beginner/
https://github.com/docker/labs/blob/master/beginner/chapters/votingapp.md