Docker - adriennelim/wikis GitHub Wiki

Introduction

...independent container platform that enables organizations to seamlessly build, share and run any application, anywhere...

  • Images can be built from scratch e.g. your application or pulled from public repositories e.g. node, PostgreSQL etc
  • Containers are built from images, which will specify its contents but can be modified.

Resources

Docker Terminal Commands

View images (local machine)

docker images

Remove an image

docker rmi container_id (or container_name)

View current running containers (local machine)

docker ps

View all containers, including stopped ones (local machine)

docker ps -a

Stop a running container

docker kill container_id (or container_name)

Start a stopped container

docker start container_id (or container_name)

Remove a container

docker rm container_id (or container_name)

Build an Image

To build an image locally from a Dockerfile (you need to set this up)
docker build -t image_name .

  • -t tag or name your image
  • . build context

To build an image locally from a file that is not named Dockerfile e.g. Dockerfile.dev
docker build -f Dockerfile.dev -t image_name .

  • -f to specify filename to build from

Create & Run Container from an Image

docker run -d image-name

  • -d for detached mode, so you get to continue working on the terminal
  • If not in detached mode, CTRL + C to stop

To Access a Container

docker exec -it container_id /bin/bash

  • Container must be running

Install Vim in a Container

docker exec -it container_id /bin/bash
apt-get update
apt-get -y install vim

Docker Compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.

  1. Create & add config info to docker-compose.yml file
  2. To run yaml file: docker-compose up
  3. To stop & remove containers created by up: docker-compose down

Docker Setup - AWS EC2

SSH into AWS EC2 instance, then run the following commands:

1. sudo yum update -y
2. sudo yum install docker
3. sudo service docker start
4. sudo usermod -a -G docker ec2-user   
  // Log out and log back in again to pick up the new docker group permissions
5. docker info 
  // Verify that the ec2-user can run Docker commands without sudo

Building an image from a Dockerfile:

touch Dockerfile
vim Dockerfile 
// To edit Dockerfile in VIM, enter 'i'. To save and quit, <esc> + ':' + 'wq' + <enter>.

Installing Docker Compose:

1. sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2. sudo chmod +x /usr/local/bin/docker-compose
// Log out and log back in again to pick up the new docker group permissions

Building an image & container from public DockerHub images, e.g. your application:

docker build -t dockerhub_username/dockerhub_repo:tagname .
docker run -d -p 3000:3000 --name container_name image_name

Building a container from public DockerHub images, e.g. Redis, PostgreSQL, Node etc:

docker run redis // gets latest version

Docker & PostgreSQL resources

Docker Workshop - Roger Schmidt

2019-06-05 Galvanize Alumni Workshop repo

⚠️ **GitHub.com Fallback** ⚠️