Skip to content

Instantly share code, notes, and snippets.

@kantale
Created October 11, 2018 13:45
Show Gist options
  • Save kantale/23361b32092a9bcb78d736e7afb1ee2c to your computer and use it in GitHub Desktop.
Save kantale/23361b32092a9bcb78d736e7afb1ee2c to your computer and use it in GitHub Desktop.
Docker

Install docker

sudo apt install docker.io

Create Dockerfile

Example:

FROM ubuntu:16.04

RUN apt-get update 

RUN apt-get install -y gcc make g++ 

Create (build) an image

sudo docker build -t mitsos .

Show all images

sudo docker images

Create a container and run it!

sudo docker run -i -t mitsos

Create a container and run a specific BASH command

sudo docker run -t mitsos /bin/bash -c "ls -la /root"

Deattach from a container:

ctrl-p ctrl-q

SHOW all containers

sudo docker ps -a

Reattach to a running container

sudo docker attach 03a0d9c58ada

Copy a file to a running container

sudo docker cp myfile 03a0d9c58ada:/root/myfile

Copy a from from a running container

sudo docker cp 03a0d9c58ada:/root/HELLO ./

Share a directory from local in the container

sudo docker run -i -v /home/ubuntu/mydata:/mydata -t mitsos

IMPORTANT The container can write to the files

Delete an exited container

sudo docker rm edb7389e52f4

Run a command in a running container

sudo docker exec -i -t afe3b21735a0 ls -l

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment