$ docker run --rm ubuntu echo "Hello world"
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
6a5697faee43: Pull complete
ba13d3bc422b: Pull complete
a254829d9e55: Pull complete
Digest: sha256:b709186f32a3ae7d0fa0c217b8be150ef1ce4049bf30645a9de055f54a6751fb
Status: Downloaded newer image for ubuntu:latest
Hello world
docker run --rm ubuntu echo "Hello world"
ubuntu
echo "Hello world"
ubuntu
with tag latest
docker.io
) and pull it$ docker run --rm ubuntu echo "Hello world"
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
6a5697faee43: Pull complete
ba13d3bc422b: Pull complete
a254829d9e55: Pull complete
Digest: sha256:b709186f32a3ae7d0fa0c217b8be150ef1ce4049bf30645a9de055f54a6751fb
Status: Downloaded newer image for ubuntu:latest
Hello world
First run:
Subsequent runs:
$ docker run --rm ubuntu echo "Hello world"
Hello world
$ tldr docker
Manage Docker containers and images.
- List currently running docker containers:
docker ps
- List all docker containers (running and stopped):
docker ps -a
- Start a container from an image, with a custom name:
docker run --name {{container_name}} {{image}}
- Start or stop an existing container:
docker {{start|stop}} {{container_name}}
- Pull an image from a docker registry:
docker pull {{image}}
- Open a shell inside of an already running container:
docker exec -it {{container_name}} {{sh}}
- Remove a stopped container:
docker rm {{container_name}}
- Fetch and follow the logs of a container:
docker logs -f {{container_name}}
$ docker run --rm prologic/todo
$ docker run --rm -d prologic/todo
a0849c33ede8c97c30d5db7ca31bcaed01212c33dd84aca9ac96402300ff005c
$ docker attach a0849
$ docker run --rm -i python
print(1 + 1)
2
$ docker run --rm -it python
Python 3.9.0 (default, Oct 13 2020, 20:14:06)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
docker run --rm -d -p 5432:5432 postgres
docker run --rm -d -p 5433:5432 postgres
docker run --rm -d -p 5434:5432 postgres
docker run --rm -d -p 8000:8000 prologic/todo
docker run --name todo -d -p 8000:8000 \
-v /tmp/todo.db:/usr/local/go/src/todo/todo.db \
prologic/todo
docker stop todo
docker rm todo
docker run --name todo -d -p 8000:8000 \
-v /tmp/todo.db:/usr/local/go/src/todo/todo.db \
-e THEME=ayu \
prologic/todo
docker logs -f todo
[todo] 2020/10/23 23:56:00 (172.17.0.1:35904) "GET / HTTP/1.1" 200 842 684.422µs
[todo] 2020/10/23 23:56:00 (172.17.0.1:35904) "GET /css/color-theme.css HTTP/1.1" 200 166 196.807µs
docker inspect todo
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install nodejs npm
WORKDIR /app
COPY . .
CMD ["npm", "run", "start"]
FROM node:latest
WORKDIR /app
COPY . .
CMD ["npm", "run", "start"]
docker build . -t goweiwen/docker-workshop
docker history goweiwen/docker-workshop
docker run --rm goweiwen/docker-workshop
ENV <key>=<value>
VOLUME ["/data"]
EXPORT <port>
docker run -d --name=redis redis
docker run -d --name=db postgres:9.4
docker run -d --name=vote -p 5000:80 voting-app
docker run -d --name=result -p 5001:80
docker run -d --name=worker worker
docker run -d --name=redis redis
docker run -d --name=db postgres:9.4
docker run -d --name=vote -p 5000:80 \
--link redis:redis voting-app
docker run -d --name=result \
--link db:db -p 5001:80
docker run -d --name=worker \
--link db:db --link redis:redis worker
version: 3
services:
redis:
image: redis
db:
image: postgres:9.4
vote:
image: voting-app
ports:
- 5000:80
result:
image: result-app
ports:
- 5001:80
worker:
image: worker
docker-compose up
docker stack deploy voting-app \
-c docker-compose.yml
docker login registry.gitlab.com
docker pull registry.gitlab.com/kiasufoodies/kiasubot:0.10.0
docker run -p 5432:5432 --name onimadb \
-e POSTGRES_USER='onima' \
-e POSTGRES_PASSWORD='password' \
-d postgres
docker exec -i onimadb pg_restore -U onima -d onima < ~/onima.dump
DB_HOST=0.0.0.0 DB_USER=onima DB_PASSWORD=password yarn start
services:
minio:
image: minio/minio
command: server /data
ports:
- 9000:9000
volumes:
- minio:/data
environment:
MINIO_ACCESS_KEY: minio_access_key
MINIO_SECRET_KEY: minio_secret_key
AWS_S3_ENDPOINT=http://0.0.0.0:9000
AWS_ACCESS_KEY_ID=minio_access_key
AWS_SECRET_ACCESS_KEY=minio_secret_key
yarn start
version: '3.1'
services:
api:
image: registry.gitlab.com/kiasufoodies/kiasubot:0.5.2
...
environment:
- TZ=Asia/Singapore
- DATABASE_URL=${DATABASE_URL}
- KIASU_API_KEY=${KIASU_API_KEY}
- AWS_REGION=${AWS_REGION}
- AWS_S3_BUCKET_NAME=${AWS_S3_BUCKET_NAME}
- AWS_S3_KEY_PREFIX=${AWS_S3_KEY_PREFIX}
- GOOGLE_PLACES_API_KEY=${GOOGLE_PLACES_API_KEY}
...
build:
stage: build
rules:
- if: "$CI_COMMIT_TAG"
script:
- docker pull $CI_REGISTRY_IMAGE:latest
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag
$CI_REGISTRY_IMAGE:latest .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"
- docker push "$CI_REGISTRY_IMAGE:latest"