Table of Content
  1. Docker Installation
  2. Image
  3. Container

Recently, I start to touch the Docker technology as I had a idea with some of my friends that we want to run Spark on Docker. The reason that this blog written in English is that I run Docker on Ubuntu and there is no chinese input method installed.

Docker Installation

I installed docker using the official source. In the beginning, we need to ensure that our ubuntu apt-get is up to date.

sudo apt-get update

It is noteworthy that if we can not update the apt-get, we may be blocked by the firewall. we can apply a proxy before using the apt-get:

export http_proxy="http://user:pwd@proxyIP:port"

Or we can try to download from other ubuntu source. Open the software & update, select the best server in “download from”. After updating, we can start to install the apt-transport-https:

sudo apt-get install apt-transport-https

Then add the Docker repository key in our local machine:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

The next step, add the docker official source to our source list:

sudo bash -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"

then update apt-get again:

sudo apt-get update

If all the steps above are ok, the docker will be installed by:

sudo apt-get install -y lxc-docker

It would be a while before installation completed. When it done, we can see the docker version, the status of docker service, and turn on or turn off the docker service:

sudo docker -v
sudo service docker status
sudo service docker start
sudo service docker stop
sudo service docker restart

In the future, if we need keep the version the same up to date, we can update docker to latest version via:

sudo apt-get update -y lxc-docker

Image

After we installed the docker, we can use docker to pull the image you want. Usualy, we pull images from the Docker Hub. we can search the the image term via the formated command: “docker search TERM”. In my case, I search for a Ubuntu image:

sodu docker search ubuntu

Then, we can find many types of ubuntu listed. To pull the image using the command “docker pull NAME[:TAG]”.

sudo docker pull ubuntu:latest

if download successfully, we now get the ubuntu image with the latest tag. We can see all the images on our local machine by:

sudo docker images

It lists as:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              latest              88f79970fa20        3 weeks ago         127.2 MB

If we want to see the detail information of the image or want to remove the image, use the command:

sudo docker inspect NAME
sudo docker rmi NAME

Container

Next, we can create container runing on the image we have pulled. For example, we create a container named BIGBAI and start it:

sudo docker create -it --name BIGBAI ubuntu:latest
sudo docker start BIGBAI

To see all the container:

sudo docker ps -a

We can access a container to manipulate by “attach” command. for exmaple:

sudo docker attach BIGBAI

then we can use the bash in the container named BIGBAI. To simplify above manipulation, we also can use “run” command to create and start a container and access it immediately.

sudo docker run -it --name BIGBAI ubuntu:lastest

in this case, we are already in ubuntu bash in BIGBAI container. So the “run” can be seen as excuting “create” firstly and then excuting “start”. We can remove a container if its status is “exited”. So we need to stop the container first then remove it.

sudo docker stop BIGBAI
sudo docker rm BIGBAI

OR, we can remove it with force :

sudo docker rm -f BIGBAI

Ok, so much for today.