Practice Docker command — part-01

1. DockerFile Commands

FROM nginx:latest # Extends nginx so everything included in that image is included here
WORKDIR /usr/share/nginx/html
COPY index.html index.html
$ docker image build -t nginx-website
$ docker container run -p 80:80 --rm nginx-website
$ docker image tag nginx-website:latest btraversy/nginx-website:latest$ docker image push bradtraversy/nginx-website

2. Docker Images Commands

$ docker image ls
$ docker pull [IMAGE]
$ docker image rm [IMAGE]
$ docker rmi $(docker images -a -q)

2.1 IMAGE TAGGING & PUSHING TO DOCKERHUB

$ docker image ls
$ docker image tag nginx btraversy/nginx
$ docker image push bradtraversy/nginx
$ docker login
$ docker image tag bradtraversy/nginx bradtraversy/nginx:testing
$ docker image build -t [REPONAME] .

3. WORKING WITH CONTAINERS

$ docker container run -it -p 80:80 nginx
$ docker container run -d -p 80:80 nginx
$ docker container run -d -p 80:80 --name nginx-server nginx
$ docker container ls
$ docker ps
$ docker container ls -a
$ docker container stop [ID]
$ docker stop $(docker ps -aq)
$ docker container rm [ID]
$ docker container rm -f [ID]
$ docker container rm [ID] [ID] [ID]
$ docker rm $(docker ps -aq)
$ docker container logs [NAME]
$ docker container top [NAME]

Some sample container creation

$ docker container run -d -p 80:80 --name nginx nginx 
$ docker container run -d -p 8080:80 --name apache httpd
$ docker container run -d -p 27017:27017 --name mongo mongo
$ docker container run -d -p 3306:3306 --name mysql --env MYSQL_ROOT_PASSWORD=123456 mysql

View info on container

$ docker container inspect [NAME]
$ docker container inspect --format '{{ .NetworkSettings.IPAddress }}' [NAME]
$ docker container stats [NAME]

ACCESSING CONTAINERS

$ docker container run -it --name [NAME] nginx bash
$ winpty docker container run -it --name [NAME] nginx bash
$ docker container run -it --name ubuntu ubuntu
$ docker container run --rm -it --name [NAME] ubuntu
$ docker container start -ai ubuntu
$ docker container exec -it mysql bash
$ docker container run -it alpine sh

Cloud and DevOps Enthusiast