Getting started with docker
technical docker how toGetting started with Docker
This technical writeup should help the reader get started on working with docker.
Basic setup
We will be using Mac OSX as the host operating system for this exercise.
- Install docker toolbox. We are using version 1.8.3
- Launch a docker quickstart terminal - (docker-terminal)
Basic commands
-
List all the current running docker containers
docker ps
-
List all the docker images
docker images
-
Remove (delete) a specific docker image
# Delete a docker image docker rmi DOCKER_IMAGE_ID # A command to force delete all the images docker images | awk '{print $3}'| xargs docker rmi --force=true # A command to force delete all the previously executed containers docker ps -a | awk '{print $1}' | xargs docker rm --force=true
-
Download a specific docker container
# Download the latest version of 'centos' docker image from the docker registry docker pull centos:latest
Docker “Hello World”
- Launch a docker-terminal
-
Use centos docker image to echo a message
# Execute a docker image named 'centos' and execute the 'echo' command docker run centos echo 'Hello World!'
-
Run a docker container in background
# Execute a docker image named 'centos' # Options: # --name name to identify the running container # -i make the container interactive # - P publishes all the ports of the container # -d run the container in the background docker run --name=demo-container -i -P -d centos
-
Attach to a running container
docker attach [conatiner-name]
-
Attach to a running container in an interactive mode via a shell
docker exec -i -t [container-name] bash
Docker File
A dockerfile is a plain text document that contains all the commands a user would issue to build an image. Using docker build user can create an automated build that executes several command line instructions in succession.
# Dockerfile to build a docker image with FFmpeg framework
# ---------------------------------------------------------------------------
# Build command
# docker build -t ffmpegt --file=[dockerfile-name] .
# Run command
# docker run -it -d --name ffmpeg -P ffmpegt
# ---------------------------------------------------------------------------
FROM centos:latest
MAINTAINER kunal@finiteloop.me
ENV dlpackage http://ffmpeg.org/releases/ffmpeg-2.8.1.tar.bz2
ENV ffmpeg ffmpeg-2.8.1
ENV softwaredir /var/ffmpeg
# Download the required utilities
RUN yum install -y curl tar bzip2
# Create a directory for the software package
RUN mkdir -p ${softwaredir}
# Download the software package
RUN curl ${dlpackage} -o ${softwaredir}/${ffmpeg}.tar.bz2
RUN bunzip2 ${softwaredir}/${ffmpeg}.tar.bz2 && \
tar -xvf ${softwaredir}/${ffmpeg}.tar -C ${softwaredir}