Difference between revisions of "Docker"

From Ever changing code
Jump to navigation Jump to search
Line 3: Line 3:
= Installation =
= Installation =
To install the latest version of Docker with curl:
To install the latest version of Docker with curl:
<source>
<source lang="bash">
curl -sSL https://get.docker.com/ | sh
curl -sSL https://get.docker.com/ | sh
</source>
</source>


CentOS install:
CentOS install:
<source lang="sh">
<source lang="bash">
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum clean all
sudo yum clean all
sudo yum install -y --setopt=obsoletes=0 docker-ce-17.03.1.ce-1.el7.centos \
sudo yum install -y --setopt=obsoletes=0 docker-ce-17.03.1.ce-1.el7.centos \
  docker-ce-selinux-17.03.1.ce-1.el7.centos
        docker-ce-selinux-17.03.1.ce-1.el7.centos
sudo systemctl start docker
sudo systemctl start docker
yum-config-manager --disable jenkins #disable source to prevent accidental update
</source>
</source>



Revision as of 15:46, 16 June 2018

Containers taking a world J

Installation

To install the latest version of Docker with curl:

curl -sSL https://get.docker.com/ | sh

CentOS install:

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum clean all
sudo yum install -y --setopt=obsoletes=0 docker-ce-17.03.1.ce-1.el7.centos \
         docker-ce-selinux-17.03.1.ce-1.el7.centos
sudo systemctl start docker
yum-config-manager --disable jenkins #disable source to prevent accidental update

Example of how to run Jenkins docker image

Add your user to docker group to be able to run docker commands without need of sudo

sudo usermod -aG docker yourusername

HTTP proxy

Configure docker if you run behind a proxy server. In this example CNTLM proxy runs on the host machine listening on localhost:3128. This example overrides the default docker.service file by adding configuration to the Docker systemd service file.

First, create a systemd drop-in directory for the docker service:

mkdir /etc/systemd/system/docker.service.d

Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"

If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:

Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

Flush changes:

$ sudo systemctl daemon-reload

Verify that the configuration has been loaded:

$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

Restart Docker:

$ sudo systemctl restart docker

Docker run and basic options

docker run -it --name="mycentos" centos:latest /bin/bash
# -i interactive mode                                \command to execute
# -t bind to the current terminal
# -d disconnect mode, daemon mode, detached mode
# --name="name_your_container"

Docker inspect

Shows current configuration state of a docker container.

docker inspect <container_name> | grep IPAddress
           "SecondaryIPAddresses": null,
           "IPAddress": "172.17.0.3",
                   "IPAddress": "172.17.0.3",

Attach to a docker process

If you are running eg. /bin/bash as a command you can get attached to this running docker process

docker attach mycentos 

Dockerfile

Each line RUN creates a container so if possible, we should join lines so it ends up with less layers.

vi Dockerfile
FROM ubuntu:latest
MAINTAINER user1 <user1@gmail.com>

RUN apt-get update
RUN apt-get upgrade -y

Build

sudo docker build -t pio2pio/apache .

References