docker | docker-machine | docker-compose | docker swarm cheatsheet
Used to create VMs that run docker
docker-machine create -d virtualbox machinename
Using machine you created as target
eval $(docker-machine env machinename)
docker-machine rm -f machinename
docker build -t your-image-name .
docker-compose equivalent:
docker-compose-test-local.yml
app:
build: .
image: your-image-name
docker-compose -f docker-compose-test-local.yml build app
docker images
docker-compose equivalent:
docker-compose ps
docker-compose-test-local.yml
staging-dep:
image: your-image-name
ports:
- 8080:8080
depends_on:
- db
db:
image: mongo
docker-compose -f docker-compose-test-local.yml up -d staging-dep
docker-compose-test-local.yml
staging:
extends:
service: unit
environment:
- HOST_IP=localhost:8080
network_mode: host
command: bash -c "npm i && npm test"
docker-compose -f docker-compose-test-local.yml run --rm staging
docker-compose -f docker-compose-test-local.yml down
docker-compose-test-local.yml
registry:
container_name: registry
image: registry
ports:
- 5000:5000
volumes:
- .:/var/lib/registry
restart: always
docker-compose -f docker-compose-local.yml up -d registry
Docker uses a naming convention to decide where to pull and push images from. If the name is prefixed with an address, the engine will use it to determine the location of the registry. Otherwise, it assumes that we want to use Docker Hub. Therefore, the first command pulled the alpine image from Docker Hub.
The second command created a tag of the alpine image. The tag is a combination of the address of our registry (localhost:5000) and the name of the image. Finally, we pushed the alpine image to the registry running on the same server.
# pull from docker hub
docker pull alpine
# tag an image
docker tag alpine localhost:5000/alpine
# push image to registry
docker push localhost:5000/alpine
ls -1 docker/registry/v2/repositories/alpine/
The output is as follows.
_layers
_manifests
_uploads