Docker
Docker image and container command line interface.
Table of Contents
Install docker
Refer
# 1. Install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt install ca-certificates curl gnupg lsb-release
# 2. Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 3. add docker source
echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 4. Install docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
# 5. Setup permissions & logout then login.
sudo groupadd docker
sudo usermod -aG docker $USER
Docker commands
# docker image registry
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
docker push manid2.gitlab.io/app:latest
docker pull manid2.gitlab.io/app:latest
# docker build
docker build --pull -t manid2.gitlab.io/app:latest .
# docker tag image
docker tag manid2.gitlab.io:latest manid2.gitlab.io/app:latest
# run docker
docker run -v `pwd`:/src/ manid2.gitlab.io/app:latest /src/scripts/app-tests
# access service in docker from host
docker run -p 1313:1313/tcp -it -v `pwd`:/src/ manid2.gitlab.io/app:latest \
/src/scripts/app-serve
docker run -p $HOST_IP:1313:1313/tcp -it -v `dirname $PWD`:/src/ \
manid2.gitlab.io/app:latest /src/manid2.gitlab.io/scripts/app-serve
# in docker containr run
# hugo server --bind 0.0.0.0 --baseURL $HOST_IP
# list all docker containers
docker ps
# list all docker images
docker images
# remove docker image
docker rmi manid2.gitlab.io/app:latest
# stop docker containers
docker stop manid2.gitlab.io/app:latest
# kill docker containers
docker kill --signal=SIGKILL manid2.gitlab.io/app:latest