DOCKER

About

Docker solves the issue of an application running on one platform but not on others. This is achieved by taking a docker ‘Image’, which contains a list of all the software you want in a particular case, and using it tp spin up a docker “Container”. Docker Hub is a repository of all these images

Installation

On ubuntu it’s just sudo apt-get docker.io

Hello world

Pulling an image

It’s just docker pull <imagename>. That pulls from dockerhub

Creating a container from the image

docker run <imagename> creates a container from the image

Start the container

The command here is docker run --name <myprocessname> -it <containername> bash

docker is opening the docker software run is executing the docker software’s run command --name <myprocessname is assigning whatever name you want to the process -it puts you in interactive mode so you can issue commands inside the container <containername> is the name of the container you created bash tells it you want to run bash in the container

Stop the container

sudo docker stop MyContainer

Kill the container

sudo docker kill MyContainer

Remove the container

sudo docker rm MyContainer

Start the container

sudo docker stop <container>

Get logs from a container

sudo docker logs <container> -f

View network information for container

sudo docker inspect <container> -f "{{json .NetworkSettings.Networks }}"

Add container to network

sudo docker network connect <network> <container>

SSH into existing contianer

docker exec -it container_ID_or_name /bin/bash

List all the images you have

sudo docker images

Commit changes to a container

docker commit <hash> <new-container-name>

Run container with a volume

docker run --name <name> -it -v <localpath>:<container-path>/ <image> bash

Images

Alpine

Docker-compose

References