References:
https://github.com/docker/labs/
Check docker info, version, client and server versions, etc
docker info
docker --version
docker version
docker pull alpine
docker run alpine ls -la
docker run -it alpine /bin/sh
This command will docker pull nginx
, then run container exposing port 80.
docker run -d -p 80:80 --name webserver nginx
-d
detached mode (demonized)-p
port--name
to give container a name, we can quickly start, stop, remove this container with this name from next time.
running processes
docker ps
see all processes (running/stoped)
docker ps -a
docker images
docker port webserver
Stop webserver
container that is running in port 80
docker stop webserver
Start container
docker start webserver
Stop and remove container at once
docker rm -f webserver
$ docker run -d -p --name static-site -e AUTHOR="first container" dockersamples/static-site
2d902f63d29ace61c2f47f3c26f9b9647713dd8191a82e5591e3410522955c59
$ docker port static-site
443/tcp -> 0.0.0.0:32768
80/tcp -> 0.0.0.0:32769
# You can run browse this application in http://localhost:32769
$ docker run -d -p 80:80 --name static-site-2 -e AUTHOR="second container" dockersamples/static-site
a14804b930eed01837a4c803f74cd72591a251809819f92baa9877d5c20c2304
Here we are pulling dockersamples/static-site image from cloud. First docker run
command
will run static site application in random port, to see port number we used docker port static-site
.
According to our example the port used is 32769
and we can see output in http://localhost:32769.
We run another container for same image but this time we specify port as 80
. So this time
we can see output in http://localhost:32769.
In the above command:
-d
will create a container with the process detached from our terminal-P
will publish all the exposed container ports to random ports on the Docker host-e
is how you pass environment variables to the container--name
allows you to specify a container nameAUTHOR
is the environment variable name and Your Name is the value that you can pass
Let's use shortcut to remove second site
docker rm -f static-site-2
docker images
By default latest
images will be pulled. To pull specific version of image,
we need to specify version number.
docker pull ubuntu:12.04
You can search images in https://store.docker.com/. Or using command line:
docker search nginx
Please check [Build Ruby on Rails image](todo add url) if you are interested.
If you have Dockerfile
you can use docker build
to build your image
docker build -t przbadu/demoApp .
Here,
-t
specify tag, convention is to use /imagename.
specify the path of the Docker file, if Docker file is in current directory, then we can use.
otherwise/path/to/Dockerfile
.
Now we can run this image using:
$ docker run -p 8888:5000 --name myfirstapp YOUR_USERNAME/myfirstapp
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
First you need to login
docker login
And then push,
docker push przbadu/myfirstapp
docker rm -f myfirstapp
docker rmi przbadu/myfirstapp
docker-compose up -d
In detached mode