$ docker
$ docker version
$ docker run -it -p 80:80 nginx
docker run
command lets you run any Docker image as an container. In this example we're using the following options in addition:-it
: executes the container in interactive mode (not in the background).-p 80:80
: by using the -p option we're connecting the internal port 80 of the container the the external port 80. Because the Nginx server by default is running on port 80 we're then able to send HTTP request to the server from our local machine by opening up URL http://localhost:80. It's also possible to connect an internal port to any other external port, e.g. connecting internal port 80 to external port 8080 (-p 8080:80). In this case we need to access http://localhost:8080.$ docker ps
$ docker rm [CONTAINER_ID]
CTRL+C
in the terminal instance in which the container has been started. Now it is possible to delete the container by using the docker rm
command.$ docker images
$ docker images rm [IMAGE_ID]
docker pull
command:$ docker pull nginx
$ docker run -d -p 80:80 nginx
docker ps
. In order to stop the the detached container you need to use the following command:$ docker stop [CONTAINER_ID]
$ docker ps -a
$ docker run -d -p 80:80 --name mynginx01 nginx
$ docker stop mynginx01
$ docker start mynginx01
docker exec
command. In the following example we're using that command to start a bash terminal for our running container myngin01.$ docker exec -it mynginx01 bash
# cd usr/share/nginx/html/
# cat index.html
$ mkdir html
$ cd html
$ touch index.html
$ docker run -d -p 80:80 -v ~/Projects/docker/html:/usr/share/nginx/html --name nginx-with-custom-content nginx
-v [HOST_PATH]:[CONTAINER_PATH]
$ docker run -d -p 80:80 -v ~/Projects/docker/html:/usr/share/nginx/html -v ~/Projects/docker/logs:/var/log/nginx --name nginx-with-custom-content nginx
~/Projects/docker/logs
. Here we should be able to find at least the file access.log which is containing the log output of the Nginx server which is running in the container:$ touch Dockerfile
$ docker build -t mynginx_image1 .
docker run
command once again in the following way:$ docker run --name mynginx -p 80:80 -d mynginx_image1
docker
command on the command line to login by using$ docker login
$ docker tag [image] [username/repository:tag]
$ docker tag mynginx_image1 codingthesmartway/mynginx_image1
$ docker push codingthesmartway/mynginx