BIP KB:
How To - Install And Get Started With Docker


img

install docker VPS | BIP media

Install Docker VPS

Install Docker VPS. If you use Linux, setting up Docker VPS is fairly easy. You can find great instructions straight from Docker's website here. You can also set up Docker on MacOS and Windows - it's a little more complicated, so I recommend using Vagrant's new Docker support feature.


 

Docker Online Documentation

Docker has great documentation and a useful interactive online tutorial.

Using The Repository

The repository of images with your Docker VPS Server is one of it's best features. The images can be downloaded directly using the pull command and used as the basis of containers for running applications or programming environments (ie. with an ubuntu image you can run containers with ubuntu). If you want to download an ubuntu Docker image, all you have to do is type this into terminal:
1 $ docker pull ubuntu
  If you get a permission denied error, add sudo before Docker in your commands, like below:
1 $ sudo docker pull ubuntu
Pulling images for the first time is similar to cloning a github repository. With the line above, you downloaded an ubuntu image with various versions of ubuntu, such as 14.04, 13.10 and so on. It probably took a few minutes. You can also be more specific and download only the version you need. In Docker, versions are marked with tags. For example, to download a specific debian box, write:
1 $ docker pull debian:squeeze
To see what Docker images are available on your machine, write:
1 $ docker images
2 
3 ubuntu                           14.10                                      f14704ad99b8    3 days ago          226.8 MB
4 ubuntu                           utopic                                     f14704ad99b8    3 days ago          226.8 MB
5 ...


Docker VPS Run Command

After downloading an image, you can run it using Docker VPS with run command, which looks like:
1 $ docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
Use this to test the image with a simple ls command run on your Docker VPS image:
1 $ docker run -t ubuntu:14.04 ls
2 
3 bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
4 boot  etc  lib   media  opt  root  sbin  sys  usr
Congratulations! You've just run your first command on Docker container. To try your container interactively, use:
1 $ docker run -t ubuntu:14.04
or
1 $ docker run -i -t ubuntu:14:04 /bin/bash
Now you have the newest ubuntu with root access at your fingertips. Try some commands like pwd or cd to make sure that it works. You can close it anytime by typing Ctrl-D or exit.

Running A Redis Container

Now that you know the basics, we can proceed with a more sophisticated example. Imagine that you want to run Redis in our container. (Redis is simple but powerful key-value store. You can read more about it here.) You can find its image in registry using Docker's search command:
1 $ docker search redis
You'll notice the command prints almost eight houndred images!
1 $ docker search redis | wc -l
2 779
Choose one of the most popular images: dockerfile/redis. Next, create your container. There are three requirements:
  • Should run as deamon
  • Data can't disappear when you restart your container
  • Should bind to the network to be accessible
The first requirement is very simple. Just pass a -d flag to your docker run command. For the second requirement, map a host directory to a directory in your container where it stores data. From this readme on dockerfile/redis you probably know that a Redis image is configured to store data in the/data directory. That means you must:
  • create a directory on your host system
  • map directories between your host system and the Docker container so that they instantly synchronize (the change from Docker will appear on your host and vice versa).
Creating a directory is simple:
1 $ mkdir /var/docker/redis
You can mount by:
1 $ docker run -v /host_directory:/container_directory docker_image
2 
3 $ docker run -d -v /var/docker/redis:/data dockerfile/redis
You can find more information about docker volumes here. The last part is networking. Redis uses port 6379 by default, so you have to forward this port to make it accessible from your computer. To forward $CONTAINERPORT to $HOSTPORT on your computer use:
1 $ docker run -p $HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage
For this example, it should look like:
1 $ docker run -d -v /var/docker/redis:/data -p 6379:6379 --name=redis dockerfile/redis
And you're done! You can check if your Redis container works with Redis desktop manager or Webdis - both are pretty cool tools that you should check out if you use Redis.

Getting More Info About Docker Containers

To see which Docker containers are on your computer, type:
1 $ docker ps -a
This will show you:
  • CONTAINER ID - every container has unique id
  • IMAGE - image that container is based on
  • NAMES - names given to your container (Docker gives funny names to your containers if you don't provide your own by passing --name container_name in the run command)
  • COMMAND - what command container runs inside
  • CREATED - when the container was created
  • STATUS - containers can be in two states: exited or running
  • PORTS - exposed and forwarded ports
That's a lot's of information! But wait, there's more. Let's spy a bit on our container with the inspect command.
1 $ docker inspect <docker_container_id or name>
If you run a Redis container with the --name flag, you can inspect it with the below command:
1 $ docker inspect redis
This prints a lot of useful information, including the configuration of the container, its environment variables, forwarded ports, mounted volumes, container constraints, and so on. Below is only small fragment of what you can see:
 1 ...
 2 "NetworkSettings": {
 3     "Bridge": "docker0",
 4     "Gateway": "172.17.42.1",
 5     "IPAddress": "172.17.0.143",
 6     "IPPrefixLen": 16,
 7     "PortMapping": null,
 8     "Ports": {
 9         "6379/tcp": [
10             {
11                 "HostIp": "0.0.0.0",
12                 "HostPort": "6379"
13             }
14         ]
15     }
16 },
17 "Path": "redis-server",
18 "ProcessLabel": "",
19 "ResolvConfPath": "/etc/resolv.conf",
20 "State": {
21     "ExitCode": 0,
22     "FinishedAt": "0001-01-01T00:00:00Z",
23     "Paused": false,
24     "Pid": 13335,
25     "Running": true,
26     "StartedAt": "2014-10-03T10:16:20.834865727Z"
27 },
28 "Volumes": {
29     "/data": "/var/docker/redis"
30 },
31 ...
The other valuable commands are:
1 $ docker logs redis
Which will let you see what container prints to STDIO and STDOUT, and
1 $ docker top redis
Which tells you what processes are currently running on you Docker container. It's similar to a unix tool called top.

What To Do Next

We've covered so much information about Docker, yet we've only scratched the surface! To learn more, check out this docker cheatsheet and the materials from warsjawa workshops - they will blow you away with helpful information!


Tags: , , , , , , , , , ,

Spin up a VPS server in no time flat

Simple setup. Full root access. Straightforward pricing.

DEPLOY VPS SERVER

Leave a Reply



Feedbacks