Skip to main content

General Docker Information

====================================================================================

To preface this page; I personally recommend trying out Portainer, which is essentially a web GUI for Docker - it's great. Portainer even lives in a docker container itself.

Regarding images and container management; the contents of this page are great if you're working with a small number of containers that are being installed/setup as a one-off then this is all fine, however, if you're launching containers for applications that need to be updated, changed/customised etc then you're probably best off taking a look at the Docker Compose page.

====================================================================================

Installation

https://docs.docker.com/engine/install/ 

1. Configure Docker repo (See above link)

2. Install Docker CE (Community Edition)

apt install docker.io

Alternatively, there is a script to perform an automated installation of Docker; Again, see above link.

====================================================================================

Commands & Usage

-----------------------------------------------------------------------------------------------------------------------------

Managing Containers

List Docker processes/containers (running and stopped)
docker ps -a
Start a container
docker start containername
stop a container
docker stop containername
Delete a container
docker rm containername
Check container performance metrics
docker stats containername

-----------------------------------------------------------------------------------------------------------------------------

Adding new docker images

Docker has their own 'marketplace' of sorts for docker images:

https://hub.docker.com/ 

To install a new docker image

This won't start a container based on the image. Instead, the image is just added to the locally stored images.

docker pull container-name
List installed Docker images
docker images
Search locally installed images, and search Docker repository for available images
docker search name

Launching Containers


To launch a new container, we can use the docker run command. The docker run command will search for locally installed images, and it can also search the docker marketplace if no local image is found.

A basic example of using docker run to pull an image (basic hello-world container) from the market place;

root@test:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:91fb4b041da273d5a3273b6d587d62d518300a6ad268b28628f74997b93171b2
Status: Downloaded newer image for hello-world:latest

Hello from Docker!

 

Basic launch for a container based on an image

docker run --name containername -it imagename

There are lots and lots of options available for the docker run command:

Starting an instance with this method will push your shell into the container itself. To exit the container (continues running):

ctrl+p ctrl+x

To connect to a docker image:

docker attach containername

To connect to a docker image CLI:

docker exec -it containername bash

====================================================================================

====================================================================================