Cloud Computing‎ > ‎

Docker












Install Docker


 

sfuser@consul-docker:~$ sudo curl -sSL https://get.docker.com/ | sh


Processing triggers for libc-bin (2.19-0ubuntu6) ...

Processing triggers for ureadahead (0.100.0-16) ...

+ sudo -E sh -c docker version

Client:

Version:      1.8.1

API version:  1.20

Go version:   go1.4.2

Git commit:   d12ea79

Built:        Thu Aug 13 02:35:49 UTC 2015

OS/Arch:      linux/amd64



Server:

Version:      1.8.1

API version:  1.20

Go version:   go1.4.2

Git commit:   d12ea79

Built:        Thu Aug 13 02:35:49 UTC 2015

OS/Arch:      linux/amd64



If you would like to use Docker as a non-root user, you should now consider

adding your user to the "docker" group with something like:



  sudo usermod -aG docker sfuser



Remember that you will have to log out and back in for this to take effect!



sfuser@consul-docker:~$

sfuser@consul-docker:~$ sudo usermod -aG docker sfuser


Get docker info


 

sfuser@consul-docker:~$ docker info

Containers: 1

Images: 2

Storage Driver: aufs

Root Dir: /var/lib/docker/aufs

Backing Filesystem: extfs

Dirs: 4

Dirperm1 Supported: false

Execution Driver: native-0.2

Logging Driver: json-file

Kernel Version: 3.13.0-32-generic

Operating System: Ubuntu 14.04.1 LTS

CPUs: 1

Total Memory: 1.955 GiB

Name: consul-docker

ID: QJ72:MQ5H:OIGU:RA2T:U3OC:DHQ4:6X3Q:G733:W4TQ:BKHV:K2O4:SCS2

WARNING: No swap limit support


List docker container


 

sfuser@consul-docker:~$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES


Create ubuntu Docker Container


The -i flag starts an interactive container. The -t flag creates a pseudo-TTY that attaches stdin and stdout.

To detach the tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q.

The container will continue to exist in a stopped state once exited.

To list all containers, stopped and running use the docker ps -a command.


 

sfuser@consul-docker:~$ docker run -it ubuntu bash

Unable to find image 'ubuntu:latest' locally

latest: Pulling from library/ubuntu

6071b4945dcf: Pull complete

5bff21ba5409: Pull complete

e5855facec0b: Pull complete

8251da35e7a7: Pull complete

Digest: sha256:1572e29178048ad9ab72e78edd4decc91a3d8a8dea0ca39817efc7cf2d86c6d7

Status: Downloaded newer image for ubuntu:latest

root@8586cac8e2aa:/#

root@8586cac8e2aa:/#

root@8586cac8e2aa:/# docker ps

bash: docker: command not found

root@8586cac8e2aa:/# ifconfig

eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02

          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0

          inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:59 errors:0 dropped:2 overruns:0 frame:0

          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:9644 (9.6 KB)  TX bytes:816 (816.0 B)



lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)



root@8586cac8e2aa:/# exit

exit

sfuser@consul-docker:~$ docker ps


List of Docker Containers


 

sfuser@consul-docker:~$ docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

8586cac8e2aa        ubuntu              "bash"              6 minutes ago       Exited (0) 4 minutes ago                       jolly_franklin

1b83d78dbd90        hello-world         "/hello"            8 minutes ago       Exited (0) 8 minutes ago                       adoring_fermi



Simple Web service with Docker


 

sfuser@consul-docker:~$ cd docker-sample/

sfuser@consul-docker:~/docker-sample$ pwd

/home/sfuser/docker-sample


#Create a small file called Dockerfile with below contents

sfuser@consul-docker:~/docker-sample$ cat Dockerfile

FROM  python:3

EXPOSE  80

CMD ["python3", "-m", "http.server"]


#In the same directory as this file execute:

sfuser@consul-docker:~/docker-sample$ docker build -t python3/server .

Sending build context to Docker daemon 2.048 kB

Step 0 : FROM python:3

---> 545faa5764ae

Step 1 : EXPOSE 80

---> Using cache

---> 4faf813a70fa

Step 2 : CMD python3 -m http.server

---> Using cache

---> 6973d0271dad

Successfully built 6973d0271dad


#This will build the docker container and call it python/server, which can be run with:

sfuser@consul-docker:~/docker-sample$ docker run -it -p 8000:80 python3/server

Serving HTTP on 0.0.0.0 port 8000 ...


#To test that it is running we can call the service with curl:

sfuser@consul-docker:~$ curl http://0.0.0.0:8000

curl: (52) Empty reply from server


Docker commands


Stop container

$docker stop <container name>


Start container

$docker start <container name>


Delete container

$docker rm <container name>


Delete all container

$docker rm $(docker ps -aq)


List running containers

$docker ps


List all containers

$docker ps -a


List all container id

$docker ps -aq