Docker - adriennelim/wikis GitHub Wiki
...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.
docker images
docker rmi container_id
(or container_name)
docker ps
docker ps -a
docker kill container_id
(or container_name)
docker start container_id
(or container_name)
docker rm container_id
(or container_name)
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
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
docker exec -it container_id /bin/bash
- Container must be running
docker exec -it container_id /bin/bash
apt-get update
apt-get -y install vim
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.
- Create & add config info to
docker-compose.yml
file - To run yaml file:
docker-compose up
- To stop & remove containers created by
up
:docker-compose down
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
2019-06-05 Galvanize Alumni Workshop repo