Docker
Open your favorite Terminal and run these commands. Installing docker on Mac with Homebrew Cask:
brew install docker --cask
Get docker version:
docker --version
If the above command doesn’t return the Docker version, you may need to start the Docker daemon first. You can do that by searching for Docker in Spotlight or in the Application folder in Finder and running it. Get docker info:
docker info
Create a docker image: Before creating a docker image, make sure to add a Dockerfile in the current directory
docker build -t golang-docker .
Run a docker image:
docker run -d -p 80:80 golang-docker
List all images docker images:
docker images
Check the running processes:
docker ps
Stop a running process:
docker stop 35a3173485aa
Login in docker hub:
docker login
Tag an image to make it ready for pushing to docker hub:
docker tag golang-docker mnkrana/golang-docker:latest
Push tagged image to docker hub:
docker push mnkrana/golang-docker
Login in github docker packages: First, export your personal access token from developer setting in github. Then, export it like this
export PAT=<your PAT>
Now, to login
echo $PAT | docker login ghcr.io --username phanatic --password-stdin
Push to github packages: Make sure to tag your image with ghcr.io like this
docker tag golang-docker ghcr.io/mnkrana/golang-docker
Now, push it to github packages:
docker push ghcr.io/mnkrana/golang-docker2:latest
Remove docker image:
docker image rm -f mnkrana/golang-docker
Show all containers:
docker ps -a
Delete all containers:
docker rm -f $(docker ps -a -q)
Prune docker system:
docker system prune -a
Check logs
docker run --name test -d -p 80:80 golang-docker
docker logs -f test
Inspect running container
docker inspect <container-name>