Docker

Last Edited Time
Feb 9, 2022 06:18 AM
date
Apr 3, 2019
slug
docker
status
Published
tags
Docker
Notebook
Command
summary
docker 常用命令, 以及缓存等
type
Post

Start Docker

systemctl enable docker
systemctl start docker

Shadowsocks with docker (mritd/shadowsocks)

docker run -dt --name shadowsocks -p 8381:8381 mritd/shadowsocks -s "-s 0.0.0.0 -p 8381 -m aes-256-cfb -k sjy1125 --fast-open"

docker images

docker ps -a

docker stop shadowsocks

docker rm shadowsocks

docker exec -it shadowsocks /bin/bash

Modify Dockerfile and create new docker

# current folder has dockerfile
cd notebook/shadowsocks/docker

# remove image
docker rmi DOCKER_IMAGE_ID
# create image from dockerfile
docker build -t shadowsocks:0.0.1 .

Run this image

# run & interact with that docker image
docker run -it DOCKER_IMAGE_ID

# run & interact with that docker image without default CMD
docker run -it --entrypoint=/bin/bash DOCKER_IMAGE_ID -i

docker run -dt --name shadowsocks -p 8381:8381 -p 8382:8382 -p 8383:8383 -p 8384:8384 -p 8385:8385 DOCKER_IMAGE_ID

# interact with docker container
docker exec -it shadowsocks /bin/sh

Docker Compose

Create Containers

docker-compose -f docker-compose.yml up

docker-compose up -d

docker logs shadowsocks

Docker registry

Example

# start redis and map related port
docker run -d --name redis -p 6379:6379 redis

# docker logs
docker logs -f --tail 100 87b4bef8cd8c

Issue

Error: could not get uid/gid

Sometime npm install in Docker will throw Error: could not get uid/gid error
solution: use npm i --unsafe-perm=true instead

Error

docker 在构建镜像的时候会尝试使用上次的缓存(intermediate container), 如果上次构建失败的情况下, 尝试清除缓存构建
# 方法一: 使用 --no-cache
docker build --no-cache

# 方法二: 清空 image 缓存
docker images purge

# 其他清除方法:

## 清理所有停止的容器
docker container prune

## 清理所有不用数据(停止的容器,不使用的volume,不使用的networks,悬挂的镜像)
docker system prune -a