Docker

General Commands

Containers

List running containers

docker ps

List all containers

docker ps -a

Run a container from an image

docker run [OPTIONS] imagename[:tag]

Options:

Restart container

docker start container-name

Stop a container

docker stop container-name

Remove a container

docker rm myubuntu

Images

List images

docker images

Remove image

docker rmi IMAGE_ID

Build image

sudo docker build -t image_name .

Building a first setup

Bulding a container

sudo docker build -t CONTAINER_NAME .

-t is the container "tag" name
. assumes the "Dockerfile" is in the same directory as the PWD

 

Running and opening a container

docker run -it --rm CONTAINER_NAME bash

-it interactive terminal like bash
--rm removes the container after exiting