Juniper - Intro to Docker

Resources:

Juniper YouTube

TABLE OF CONTENTS

Table of Contents

What is Docker

What is Docker

  • Docker is an open-source tool used to package, move, deploy, network, secure and run containers

  • Docker makes Linux containers easy to use

    • Easy to develop applications on one system and easily deploy them across a very large number of different systems

  • Docker comes in 2 editions:

    • Community Edition: (CE)

      • ideal for developers and small teams starting with docker

      • Free - Open Source

    • Enterprise Edition:(EE)

      • Designed for enterprise development and IT teams who build, ship and run business-critical applications in production and scale ( has more tools for eg better securing images etc)

      • Licensed

    • Docker uses a Client-Server Architecture

      • CLI interface is the client (actually uses the REST API to talk to the daemon)

      • dockerd daemon is the server (all functionality is provided by this daemon that exposes a REST API (Representational State Transfer)

  • Docker - Basic Concepts

    • Docker images are used to create docker containers

    • Docker containers are runtime instances of an image

    • A Dockerfile is used to create a new docker image

    • Docker images can be stored and distributed to others on Docker Hub

  • Docker Hub

    • Repository for private, public and official images

      • Private:

        • Subscription based

        • Naming convention: user-name/image-name:tag

      • Public:

        • Free

        • Naming convention: user-name/image-name:tag

      • Official:

        • Sponsored by Docker and major vendor

        • Naming convention: image-name:tag

          • eg. Ubuntu, MySQL, REDIS, NGINX, Python, Jenkins etc

Remove Old Versions Completely

We are going to install Docker from scratch so we can uninstall older versions: Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:

Uninstall Old Versions

sudo apt list | grep docker
sudo apt remove --purge docker docker-engine docker.io containerd runc

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. If you do not need to save your existing data, and want to start with a clean installation?

sudo apt-get purge docker-ce docker-ce-cli containerd.io

Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

sudo rm -rf /var/lib/docker 
sudo rm -rf /var/lib/container

Install Docker

Install - Method 1 - Github

There a re a couple of options to install docker. The simplest is to go to the docker github repository at github.com/docker and inside there is a repo called 'docker-install' and this is just a script that will install docker for you.

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

Install - Method 2 - APT INSTALL

  • Setup Repository:

sudo apt update -y
sudo apt dist-upgrade -y 
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common 
  • Add Dockers Official GPG Key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • Setup the stable repository:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update -y
  • Install Docker

sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl status docker

Install Docker Compose

Download the latest version (in this case it is 1.29.2 of version 1) The latest versions are v2 however completely rewitten from v1, so will use this for the time being.

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Post Installation Steps: Linux

Manage Docker as a non-root user:

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user.

If you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

sudo groupadd docker
sudo usermod -aG docker $USER

Exit and login again and verify that you can run docker commands without 'sudo'

docker run hello-world

Configure Docker to Start on Boot

Most current Linux distributions (RHEL, CentOS, Fedora, Debian, Ubuntu 16.04 and higher) use systemd to manage which services start when the system boots. On Debian and Ubuntu, the Docker service is configured to start on boot by default. To automatically start docker and containerd on boot for other distros, use the commands below:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

To disable this behavior, use disable instead.

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Basic Commands

docker images - see what docker images have been pulled down locally docker pull - Pulls docker image to local environment docker container list docker image list docker version docker ps - list running containers docker run -d nginx- runs container in "detach mode" - gives back the command line to you docker run -d nginx:1.20.1 - pulls from repository and runs specific version and detaches docker stop<container id/name>- Stops container name - for ID, use docker ps docker start <container id/name> - Starts the specified container docker ps -a - Lists all containers. Good way to find container id of stopped containers docker network ls - lists the docker network docker network create mongo-network - creates a network for eg. the mongodb network

docker volume ls docker volume prune

By default docker containers are ephemeral, they will run the process to find within them and then close. To run a PERSISTENT process we can use the detached mode -d

docker run -d  -p<host port>:<container port> <image_name:tag>
docker run -d -p8080:80 nginx:1.20.2
docker run -d -p8080:80 --name nginx-older nginx:1.20.1 

Changes to names we want. In this case from wonderful_mendel to nginx-older

Here we have 2 instances of nginx running and both listening on port 80:

So, from the NGINX example, we need to map the ports when we RUN the containers. So we will need to stop both instances of NGINX, and run them again by mapping (port binding) different HOST ports to the same CONTAINER PORTS

Portainer Business Edition - Free 5 Nodes

To install business edition:

First, create the volume that Portainer Server will use to store its database:

docker volume create portainer_data
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ee:latest

Login via browser FQDN or IP on port 9443 Enter business free 5 node license key

Add in SSL Certificates

Click on Settings, scroll down to SSL Certificates > add .pem fullchain.pem and private.key

Update Portainer

Stop and remove the old version for docker standalone. Your other applications/containers wont be removed

docker stop portainer
docker rm portainer
docker ps

Run command to deploy latest: see above

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ee:latest

Log out of Portainer (if logged in) and log back in Enter your license key (the free one you got when you registered 😄)

Done !! Check bottom left corner for version running.

Add a Docker Standalone Environment

Last updated

Was this helpful?