Skip to content

Instantly share code, notes, and snippets.

@basharam
Created January 2, 2015 15:31
Show Gist options
  • Save basharam/f84d19fd5c0c16f1e1e6 to your computer and use it in GitHub Desktop.
Save basharam/f84d19fd5c0c16f1e1e6 to your computer and use it in GitHub Desktop.
Docker basic setup
Docker-basic-commands on 12.04, Docker installed via mirrors.
@basharam
Copy link
Author

basharam commented Jan 2, 2015


Docker commands


1 Check docker info
$docker info
2 list images
$docker images// show docker containers
3 list processess in container
  docker ps  // shows live containers

  $docker ps -a // stale containers
4 search ubuntu 12.04 from the docker repo publish by 3rd party developers
$ docker search ubuntu12.04

NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
jcrom/ubuntu12.04-fxos                                                                      1
mkoester/ubuntu12.04-mysql5.5                                                               0                    [OK]
mkoester/ubuntu12.04-apache2-php5                                                           0                    [OK]
mkoester/ubuntu12.04-mysql5.5client                                                         0                    [OK]
readytouch/ubuntu12.04                                                                      0
binglingjue/ubuntu12.04                                                                     0
drakkars/ubuntu12.04                                                                        0
matiasdecarli/ubuntu12.04-node-mongo2.4     A Image of Ubuntu12.04 with Node.js & Mong...   0
cglewis/ubuntu12.04                         Clean Ubuntu 12.04                              0
pete/ubuntu12.04                                                                            0
asyncee/ubuntu12.04-base                                                                    0
yaasita/ubuntu12.04-vim74                   Ubuntu 12.04 with vim installed.                0
chrismoos/ubuntu12.04-chef-solo                                                             0
nodeprimedev/ubuntu12.04-xvfb-chrome                                                        0
eyes2design/ubuntu12.04_php53_fpm_tcp3000   Alpha test of a docker hooked up with tcp ...   0
ianwcarlson/ubuntu12.04boost1.47                                                            0
chug/ubuntu12.04x64                         Ubuntu Precise Pangolin 12.04 64bit  base ...   0
chug/ubuntu12.04x32                         Ubuntu Precise Pangolin 12.04 32bit  base ...   0
synctree/base-ubuntu12.04-deploy-ruby                                                       0                    [OK]

data2:~
4 To pull stock ubuntu 12.04images.
$docker pull ubuntu:12.04

ubuntu:12.04: The image you are pulling has been verified
ed52aaa56e98: Pull complete
b875af6dcb23: Pull complete
41959ee20b93: Pull complete
f959d044ebdf: Pull complete
511136ea3c5a: Already exists
Status: Downloaded newer image for ubuntu:12.04
-or

To pull all verion from ubuntu.

$docker pull ubuntu

List downloaded images.

  $docker images
  REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
  ubuntu              12.04               f959d044ebdf        34 hours ago        130.1 MB
  ubuntu              14.04               04c5d3b7b065        2 weeks ago         192.7 MB
5 Test docker, run echo command.
$docker run -t -i ubuntu:12.04 echo "helloworld"
helloworld
$
6 Test docker containers.
$docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES


$docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
30df289fe21f        ubuntu:12.04        "echo helloworld"   50 seconds ago      Exited (0) 50 seconds ago                       drunk_cori

Note docker ps will list only active containers, using ps -a will list stale or old containers(Verify the STATUS column: Exited)

7 Remove old/stale containers which are not needed.

docker rm <CONTAINER ID>|<NAMES>

$docker rm drunk_cori
drunk_cori // prints name of the contianer as a success.
$
8 To start terminal in Contianer.
$docker run -t -i ubuntu:12.04 /bin/bash
root@7246ead6ea23:/#
root@7246ead6ea23:/#
9 Multi container(aka different FS) with custom names.
$docker run -t -i --name="brindy" ubuntu:12.04  /bin/bash
root@8c42ceef4b8f:/#

Open another termnial and type.

$docker run -t -i --name="brgr" ubuntu:12.04  /bin/bash
root@d5b5a20eb6d4:/# hostname

Open another termnial and type.

 $docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
d5b5a20eb6d4        ubuntu:12.04        "/bin/bash"         3 seconds ago       Up 2 seconds                            brgr
8c42ceef4b8f        ubuntu:12.04        "/bin/bash"         48 seconds ago      Up 47 seconds                           brindy
10 Multi commit on a container, Creates new Images.
$docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
a0992ef6c3ad        ubuntu:12.04        "/bin/bash"         37 seconds ago      Up 36 seconds                           brindy1

The above command shows that brindy1 container is active(on a different terminal.) user installed wget on top of Ubuntu1204 and ready to commit.
Note: This commit is at local docker registery.

$docker commit -a "brindy1@bla.com" -m "installed wget" a0992ef6c3ad ubutu1204_wget
7d60521d9235e37ecc88fe91a3edfc184204482df05a1bab379cede85352b0f5

$docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubutu1204_wget      latest              7d60521d9235        7 seconds ago       131.4 MB
ubuntu              12.04               f959d044ebdf        36 hours ago        130.1 MB
ubuntu              14.04               04c5d3b7b065        2 weeks ago         192.7 MB

After the commit a new image is created as shown above. Notice is that user is logged in as brindy1 container on Ubuntu:12.04 image.
Now user continues installing some other packages like ssh, curl and facter and commit the new changes to same image as provided in last commit(ubutu1204_wget).

$docker commit -a "brindy1@bla.com" -m "installed facter/ssh" a0992ef6c3ad ubutu1204_wget
8c51bfd4316e380a8ea405f9c56941c9a944979940dcec183dfac4d059d95bf0

:~$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubutu1204_wget       latest              8c51bfd4316e        4 seconds ago       167.8 MB
<none>               <none>              7d60521d9235        4 minutes ago       131.4 MB
ubuntu               12.04               f959d044ebdf        36 hours ago        130.1 MB
ubuntu               14.04               04c5d3b7b065        2 weeks ago         192.7 MB

Docker images will create a new image with lastest image_id(8c51bfd4316e) as shown above. i,e as user commit the new images old images are discarded and the new ones
will become latest images.

11 Remove Images
docker rmi <IMAGE_ID>
$ docker rmi 7d60521d9235
Deleted: 7d60521d9235e37ecc88fe91a3edfc184204482df05a1bab379cede85352b0f5
$
12 Using latest repository(After few commits).
$docker run -t -i --name="brindy1" ubutu1204_wget  /bin/bash
root@8c51bfd4316e:/#
13 Dockerfile

Visit here for Dockerfile syntax/usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment