Contents
  1. 1. Install Docker
    1. 1.1. Install Docker for Ubuntu
  2. 2. Manage Docker as a non-root user
  3. 3. Create docker image(interact on ubuntu16.04)
  4. 4. Create docker image(by dockerfile)
  5. 5. TODO
  6. 6. Reference

Docker

Install Docker

  • Docker has two editions: Community Edition(CE) and Enterprise Edition(EE)
  • CE also has two update channels, stable and edge:
    • Stable: gives you reliable updates every quarter
    • Edge: gives you new features every month

Install Docker for Ubuntu

  • Reference

  • Remove old version

    1
    sudo apt-get remove docker docker-engine docker.io
  • Install packages

    1
    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
  • Add official GPG key:

    1
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    • Verify that the key fingerprint is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.
      1
      2
      3
      4
      5
      6
      sudo apt-key fingerprint 0EBFCD88

      pub 4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
      uid Docker Release (CE deb) <docker@docker.com>
      sub 4096R/F273FCD8 2017-02-22
  • setup stable repository for amd64

    1
    2
    3
    4
    sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
  • Install docker CE

    1
    2
    sudo apt-get update
    sudo apt-get install docker-ce
  • Verify docker by hello-world

    1
    sudo docker run hello-world

Manage Docker as a non-root user

  • Reference:

  • Create docker group

    1
    sudo groupadd docker
  • Add you to the docker group

    1
    sudo usermod -aG docker $USER
  • Log out and log back in again to evaluate your group membership

  • Verify docker without sudo

    1
    docker run hello-world

Create docker image(interact on ubuntu16.04)

  • Get the target image

    1
    docker pull ubuntu:16.04
  • Run a container (if you haven’t pulled the image, it will be downloaded now)

    1
    2
    3
    4
    $ docker run -it ubuntu:16.04 /bin/bash

    -i --interactive enter interactive container
    -t --tty allocate a pseudo-TTY
  • Modify the container

    1
    2
    3
    4
    5
    6
    root@cb62d48c0687:/# echo "echo hello-world" > hello.sh
    root@cb62d48c0687:/# chmod +x hello.sh
    root@cb62d48c0687:/# ./hello.sh
    hello-world

    (DON'T exit now)
  • Check the running container

    1
    2
    3
    $ docker ps -a | head -n2
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    cb62d48c0687 ubuntu:16.04 "/bin/bash" 5 minutes ago Up 5 minutes silly_payne
  • Commit the container as image

    1
    2
    $ docker commit -m "hello-world" -a "zjunwei" cb62d48c0687 hello-u1604:v1
    sha256:be522fe570cccbcd391dfdc24c15e3e28e5951df29489ce02a9aefcbaaf8a260
  • Find the image

    1
    2
    3
    $ docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    hello-u1604 v1 be522fe570cc 2 minutes ago 120MB
  • Run as interactive

    1
    $ docker run -ti hello-u1604:v1
  • Run the image directly

    1
    2
    $ docker run hello-u1604:v1 echo abc
    abc

Create docker image(by dockerfile)

  • Create dockerfile as below

    1
    2
    3
    4
    5
    6
    FROM ubuntu:16.04
    MAINTAINER zjunwei

    ADD echo.sh /
    ENTRYPOINT ["/echo.sh"]
    CMD ["This is test for docker hello"]
  • Prepare echo.sh

    1
    2
    #!/bin/bash
    echo "hello from zjunwei"
  • Build the image name:tag

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    $ docker build . -t zjunwei/hello:v1

    Sending build context to Docker daemon 123.6MB
    Step 1/5 : FROM ubuntu:16.04
    ---> 14f60031763d
    Step 2/5 : MAINTAINER zjunwei
    ---> Using cache
    ---> 143d818b2089
    Step 3/5 : ADD echo.sh /
    ---> Using cache
    ---> ae6348251dee
    Step 4/5 : ENTRYPOINT /echo.sh
    ---> Using cache
    ---> f54009ef8c37
    Step 5/5 : CMD This is test for docker hello
    ---> Using cache
    ---> 522f17f278d7
    Successfully built 522f17f278d7
    Successfully tagged zjunwei/hello:v1
  • Find the image

    1
    2
    3
    4
    $ docker images

    REPOSITORY TAG IMAGE ID CREATED SIZE
    zjunwei/hello v1 522f17f278d7 6 minutes ago 120MB
  • Run the image (Not support interactive way)

    1
    2
    3
    $ docker run zjunwei/hello:v1

    hello from zjunwei

TODO

Reference

Contents
  1. 1. Install Docker
    1. 1.1. Install Docker for Ubuntu
  2. 2. Manage Docker as a non-root user
  3. 3. Create docker image(interact on ubuntu16.04)
  4. 4. Create docker image(by dockerfile)
  5. 5. TODO
  6. 6. Reference