docker run -dp 3000:3000 : -d detach
docker logs ${container_id}
You can watch the logs using docker logs -f <container-id>
. You’ll know you’re ready to go when you see this...
docker run -d \ --network todo-app --network-alias mysql \ -v todo-mysql-data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=secret \ -e MYSQL_DATABASE=todos \ mysql:5.7
-w /app
- sets the “working directory” or the current directory that the command will run from
run one time , start ,stop many times.
docker exec -it <mysql-container-id> mysql -p
how do we allow one container to talk to another? The answer is networking. --服务内部连接。
docker run -dp 3000:3000 `
-w /app -v "$(pwd):/app" `
node:12-alpine `
sh -c "yarn install && yarn run dev"
docker compose ,容器编排 ,把命令写的yml 文件。
version: "3.7"
services:
app:
image: node:12-alpine
command: sh -c "yarn install && yarn run dev"
ports:
- 3000:3000
working_dir: /app
volumes:
- ./:/app
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: secret
MYSQL_DB: todos
docker-compose up -d
FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py
echo -e 'FROM busybox\nRUN echo "hello world"' | docker build -
ENV PG_MAJOR=9.3
ENV PG_VERSION=9.3.4
RUN curl -SL https://example.com/postgres-$PG_VERSION.tar.xz | tar -xJC /usr/src/postgress && …
ENV PATH=/usr/local/postgres-$PG_MAJOR/bin:$PATH
ENV---前面定义的变量,后面可以用到。
entrypoint https://www.cntofu.com/book/139/image/dockerfile/entrypoint.md
Command line arguments to docker run <image>
will be appended after all elements in an exec form ENTRYPOINT
, and will override all elements specified using CMD
. 会覆盖command里面的命令。
You can override the ENTRYPOINT
instruction using the docker run --entrypoint
flag.
The WORKDIR
instruction sets the working directory for any RUN
, CMD
, ENTRYPOINT
, COPY
and ADD
instructions that follow it in the Dockerfile
.
depends_on
version: "3.9"
services:
web:
build: .
depends_on:
- db
- redis
redis:
image: redis
db:
image: postgres