一点点docker笔记
shellcurl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": [ "https://hub-mirror.c.163.com", "https://mirror.baidubce.com", "https://dockerhub.azk8s.cn" ], "insecure-registries" : [ "hub-mirror.c.163.com", "mirror.baidubce.com", "dockerhub.azk8s.cn" ] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
shellsudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
dockerfile# flask部署 FROM python:3.7 COPY . /code WORKDIR /code RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && pip install -r /code/requirements.txt # 如果太慢了再加上这句 不然镜像站有可能同步不全导致包安装失败 # -i https://pypi.tuna.tsinghua.edu.cn/ CMD gunicorn app:app -c gunicorn.conf.py --error-logfile /log/gunicorn.log
shelldocker build -t 'name' . docker run -it 'name' docker run -d 'name'
COPY | 复制文件 |
---|---|
CMD | 容器启动命令 |
ENV | 设置环境变量 |
WORKDIR | 指定工作目录 |
dockerfile# flask redis nginx mysql部署 version: '3.6' services: web: build: . container_name: web volumes: - ../logs:/log depends_on: - db - redis db: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=mx/58MFuLJ6^%.q volumes: - ./config/mysql:/docker-entrypoint-initdb.d nginx: image: nginx:1.17 volumes: - ./config/nginx/default.conf:/etc/nginx/conf.d/default.conf depends_on: - web ports: - 8888:80 redis: image: redis:5.0.8 volumes: - ./config/redis/redis.conf:/etc/redis/redis.conf command: redis-server privileged: true
shelldocker ps -aq
shelldocker stop $(docker ps -aq)
shelldocker rm $(docker ps -aq)
shelldocker rmi $(docker images -q)
shelldocker image prune --force --all # 删除所有不使用的镜像 docker container prune -f # 删除所有停止的容器
本文作者:xmmmmmovo
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 许可协议。转载请注明出处!