Docker

安装 docker

curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun

配置镜像加速器

vim /etc/docker/daemon.json
{
	"registry-mirrors": [
		"https://registry.docker-cn.com"
	]
}

systemctl restart docker

其他命令

docker version
systemctl restart docker
docker pull [选项] [ip[:port]/]仓库名[:标签]
docker images
docker ps -a
docker run -it --rm ubuntu:16.04 bash
docker run -P tomcat
docker run -p 8080:8080 --name mytomcat -d tomcat
docker rm containerId
docker rm -f containerId
docker image prune
docker container prune
docker restart containerId
docker stop containerId
docker stop containerName
docker exec -it tomcat bash
docker cp mysql:/etc/mysql .
docker logs containerName
docker logs -f containerName

Dockerfile

vim Dockerfile

FROM tomcat
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
WORKDIR /usr/local...
COPY haha.txt /usr/local/tomcat/webapp...
EXPOSE 8080

docker build -t myTomcat .

Docker 数据卷

数据卷是一个可供一个或多个容器使用的特殊目录,它绕过 UFS,可以提供很多有用的特性:

  • 数据卷可以在容器之间共享和重用
  • 对数据卷的修改会立马生效
  • 对数据卷的更新,不会影响镜像
  • 数据卷默认会一直存在,即使容器被删除
docker run -p 8080:8080 -v /usr/local/docker/tomcat/ROOT:/usr/local/tomcat/webapps/ROOT tomcat

docker run -p 3307:3306 --name mysql \
-v /usr/local/docker/mysql/conf:/etc/mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7.22

Docker Compose

Compose 定位是定义和运行多个 Docker 容器的应用。

# 安装
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

docker-compose version

vim docker-compose.yml

docker-compose.yml

version: '3'
services:
 tomcat:
  restart: always
  image: tomcat
  container_name: tomcat
  ports
   - 8080:8080
docker-compose up
docker-compose up -d
docker-compose down
docker-compose logs [-f] containerName

你可能感兴趣的:(Util,docker)