Documentation notes for using Docker https://docker.com/.
Docker is application that builds containers to host your own isolated Operating Systems. You can create your Docker Image with any service/language and deploy them to your servers. This saves time provisioning for every server.
I think the main benefit is that you could accidently mess up your docker container, and your real server won't be affected. You could just repull the image.
$ sudo docker pull debian
or Create and Run
$ sudo docker run debian
$ sudo docker run ubuntu:14.04
This is just like accessing a virtual machine, but's it's a docker container.
-
The
-tmeans seudo-tty inside the new container -
The
-imeans allows interactive mode via STDIN -
The
ubuntuis the docker container name, you can see them with$ docker images- You want to connect with from the image list
repository:tag - If you had
ubuntu:12.04andubuntu:14.04in the image list, you can connect just using ubuntu and it will appear asubuntu:latest
- You want to connect with from the image list
-
The
/bin/bashis the shell to use.$ sudo docker run -t -i debian /bin/bash $ sudo docker run -t -i ubuntu:14.04 /bin/bash
When you run this notice the "Names" column auto generated for running processes.
$ sudo docker ps
Mine created one called romantic_franklin, I can see anyone processes via:
$ sudo docker logs romantic_franklin
$ sudo docker stop romantic_franklin
$ sudo docker start romantic_franklin
Check the Status of the container
$ sudo docker ps
This will download the dependencies, and the command python app.py runs it.
Make sure you find the name of the container with $ sudo docker ps it will be
different from below.
-
The
-druns in detached mode (in the background) -
The
-Plets Docker mapp to ports exposed from the image to our host.$ sudo docker run -d -P training/webapp python app.py $ sudo docker ps
Visit http://localhost:5000
We can change the port with
$ sudo docker run -d -p 5000:5000 training/webapp python app.py
To see a port provide the name (Remember $ sudo docker ps), this is an easier way:
$ sudo docker port insane_mclean 5000
See the logs of the flask container
$ sudo docker logs insane_mclean
See the processes running in a container
$ sudo docker top insane_mclean
See the entire configuration in JSON format
$ sudo docker inspect insane_mclean
We can grab the IP address with
$ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' insane_mclean
When deleting a container it is permanent.
$ sudo docker stop insane_mclean
$ sudo docker rm insane_mclean
This will list items from the docker public repositories
$ sudo docker search lamp
We can setup this docker
$ sudo docker pull training/sinatra
Then connect
$ sudo docker run -t -i training/sinatra /bin/bash
Since we are going to exit after making a change (It's interactive mode, not running in the background),
make sure to copy the root@a1f22b0f0476:/# @<hash>
Inside docker make a change, such as install JSON
$ gem install json
So we made a simple change now commit
$ sudo docker commit -m="Added gem" -a="Jesse Boyer" a1f22b0f0476
We can also tag the image
$ sudo docker commit -m="Added gem" -a="Jesse Boyer" a1f22b0f0476 jesse/sinatra:2
See the changes (You'll see two sinatra REPOSITORIES)
$ sudo docker images
Use the newly commited container
$ sudo docker run -t -i jesse/sinatra:2 /bin/bash
$ mkdir docker
$ cd docker
$ touch Dockerfile
Include the following in Dockerfile
# This is a comment
FROM ubuntu:14.04
MAINTAINER Jesse Boyer <myself@mysite.com>
RUN apt-get update && apt-get install -y ruby ruby-dev
RUN gem install sinatra
Build the file (Make sure to check $ sudo docker images)
$ sudo docker build -t="jesse/sinatra:2" .
With an image created, we can now create containers based off that
$ sudo docker run -t -i jesse/sinatra:2 /bin/bash
You will notice that the virtual machine name is different then when you first
installed it. Mine being 3c2cb985d352 now, at first it was a1f22b0f0476.
Tag your image
$ sudo docker tag 3c2cb985d352 jesse/sinatra:dev
See https://registry.hub.docker.com/plans/
Push to the docker host
$ sudo docker push jesse/sinatra
Removing from the Hub
$ sudo docker rmi jesse/sinatra
I didn't get this far yet.