Docker commands

docker ps -> List all the running docker processes. ps means the process starts

docker run hello-world => docker run image name

docker run – p 80:80 nginx

80:80=> Port 80 on host and port 80 container

nginx is a web server running on port 80

docker stop – container id

docker start container name

Create docker image

# Sample of docker file
# Use a container with Go pre-installed
FROM quay.io/projectquay/golang:1.17

# Copy our source file into the container
COPY src/hello-world.go /go/hello-world.go

# Set the default environment variables
ENV MESSAGE "Welcome! You can change this message by editing the MESSAGE environment variable."
ENV HOME /go

# Set permissions to the /go folder (for OpenShift)
RUN chgrp -R 0 /go && chmod -R g+rwX /go

# Just documentation.
# This container needs Docker or OpenShift to help with networking
EXPOSE 8080

# OpenShift picks up this label and creates a service
LABEL io.openshift.expose-services 8080/http

# OpenShift uses root group instead of root user
USER 1001

# Command to run when container starts up
CMD go run hello-world.go
docker build .

# . current directory
show list of images => docker images

Tag docker image

docker build -t shiva:v1 .

Check the Status of a docker image

docker ps   
#  show the running container check the status field

Remove the image

docker rmi image name

Adding port

# -p (host port):(container port)
docker run -it  -p 8080:8080  quay.io/practicalopenshift/hello-world

Running the docker help page offline

docker run -p 4000:4000 docs/docker.github.io

Add name and run interactive mode

docker run -p 4000:4000 -it --name shivadoc docs/docker.github.io

Find more info about container

docker inspect (container name or ID)
you can find the ip address of the container

Stop all the container

docker ps-q
docker stop $(docker ps -q)

Remove all the containers

docker ps -aq
docker rm $(docker ps-aq)
docker image prune 
docker volume ls
docker volume ls -f dangling=true

Deploy to Private Registry

docker run -d -p 1000:1000 -name regsitry register:version

docker image tag my-imagename localhost:1000/my-imagename

docker push localhost:1000/my-imagename

docker pull localhost:1000/my-imagename

dpocker pull 192.168.1.1:1000/my-imagename