mirror of https://github.com/docker/docs.git
develop/develop-images: use "console" for shell examples
This allows for easier copying of the commands, without selecting the prompt. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
859923171c
commit
ba54a6519e
|
@ -73,8 +73,8 @@ Assuming you built the "hello" executable example by using the source code at
|
||||||
and you compiled it with the `-static` flag, you can build this Docker
|
and you compiled it with the `-static` flag, you can build this Docker
|
||||||
image using this `docker build` command:
|
image using this `docker build` command:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
docker build --tag hello .
|
$ docker build --tag hello .
|
||||||
```
|
```
|
||||||
|
|
||||||
Don't forget the `.` character at the end, which sets the build context to the
|
Don't forget the `.` character at the end, which sets the build context to the
|
||||||
|
@ -84,7 +84,7 @@ current directory.
|
||||||
> you need a Linux binary, rather than a Mac or Windows binary.
|
> you need a Linux binary, rather than a Mac or Windows binary.
|
||||||
> You can use a Docker container to build it:
|
> You can use a Docker container to build it:
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```console
|
||||||
> $ docker run --rm -it -v $PWD:/build ubuntu:20.04
|
> $ docker run --rm -it -v $PWD:/build ubuntu:20.04
|
||||||
>
|
>
|
||||||
> container# apt-get update && apt-get install build-essential
|
> container# apt-get update && apt-get install build-essential
|
||||||
|
@ -94,8 +94,8 @@ current directory.
|
||||||
|
|
||||||
To run your new image, use the `docker run` command:
|
To run your new image, use the `docker run` command:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
docker run --rm hello
|
$ docker run --rm hello
|
||||||
```
|
```
|
||||||
|
|
||||||
This example creates the hello-world image used in the tutorials.
|
This example creates the hello-world image used in the tutorials.
|
||||||
|
|
|
@ -37,7 +37,7 @@ the [Dockerfile reference](/engine/reference/builder/) page.
|
||||||
Easiest way from a fresh install of docker is to set the `DOCKER_BUILDKIT=1`
|
Easiest way from a fresh install of docker is to set the `DOCKER_BUILDKIT=1`
|
||||||
environment variable when invoking the `docker build` command, such as:
|
environment variable when invoking the `docker build` command, such as:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ DOCKER_BUILDKIT=1 docker build .
|
$ DOCKER_BUILDKIT=1 docker build .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ RUN --mount=type=ssh git clone git@github.com:myorg/myproject.git myproject
|
||||||
Once the `Dockerfile` is created, use the `--ssh` option for connectivity with
|
Once the `Dockerfile` is created, use the `--ssh` option for connectivity with
|
||||||
the SSH agent.
|
the SSH agent.
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker build --ssh default .
|
$ docker build --ssh default .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -73,21 +73,21 @@ context.
|
||||||
> a text file named `hello` and create a Dockerfile that runs `cat` on it. Build
|
> a text file named `hello` and create a Dockerfile that runs `cat` on it. Build
|
||||||
> the image from within the build context (`.`):
|
> the image from within the build context (`.`):
|
||||||
>
|
>
|
||||||
> ```shell
|
> ```console
|
||||||
> mkdir myproject && cd myproject
|
> $ mkdir myproject && cd myproject
|
||||||
> echo "hello" > hello
|
> $ echo "hello" > hello
|
||||||
> echo -e "FROM busybox\nCOPY /hello /\nRUN cat /hello" > Dockerfile
|
> $ echo -e "FROM busybox\nCOPY /hello /\nRUN cat /hello" > Dockerfile
|
||||||
> docker build -t helloapp:v1 .
|
> $ docker build -t helloapp:v1 .
|
||||||
> ```
|
> ```
|
||||||
>
|
>
|
||||||
> Move `Dockerfile` and `hello` into separate directories and build a second
|
> Move `Dockerfile` and `hello` into separate directories and build a second
|
||||||
> version of the image (without relying on cache from the last build). Use `-f`
|
> version of the image (without relying on cache from the last build). Use `-f`
|
||||||
> to point to the Dockerfile and specify the directory of the build context:
|
> to point to the Dockerfile and specify the directory of the build context:
|
||||||
>
|
>
|
||||||
> ```shell
|
> ```console
|
||||||
> mkdir -p dockerfiles context
|
> $ mkdir -p dockerfiles context
|
||||||
> mv Dockerfile dockerfiles && mv hello context
|
> $ mv Dockerfile dockerfiles && mv hello context
|
||||||
> docker build --no-cache -t helloapp:v2 -f dockerfiles/Dockerfile context
|
> $ docker build --no-cache -t helloapp:v2 -f dockerfiles/Dockerfile context
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
Inadvertently including files that are not necessary for building an image
|
Inadvertently including files that are not necessary for building an image
|
||||||
|
@ -664,7 +664,7 @@ RUN echo $ADMIN_USER > ./mark
|
||||||
RUN unset ADMIN_USER
|
RUN unset ADMIN_USER
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run --rm test sh -c 'echo $ADMIN_USER'
|
$ docker run --rm test sh -c 'echo $ADMIN_USER'
|
||||||
|
|
||||||
mark
|
mark
|
||||||
|
@ -687,7 +687,7 @@ RUN export ADMIN_USER="mark" \
|
||||||
CMD sh
|
CMD sh
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run --rm test sh -c 'echo $ADMIN_USER'
|
$ docker run --rm test sh -c 'echo $ADMIN_USER'
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -762,13 +762,13 @@ CMD ["--help"]
|
||||||
|
|
||||||
Now the image can be run like this to show the command's help:
|
Now the image can be run like this to show the command's help:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run s3cmd
|
$ docker run s3cmd
|
||||||
```
|
```
|
||||||
|
|
||||||
Or using the right parameters to execute a command:
|
Or using the right parameters to execute a command:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run s3cmd ls s3://mybucket
|
$ docker run s3cmd ls s3://mybucket
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -819,19 +819,19 @@ This script allows the user to interact with Postgres in several ways.
|
||||||
|
|
||||||
It can simply start Postgres:
|
It can simply start Postgres:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run postgres
|
$ docker run postgres
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, it can be used to run Postgres and pass parameters to the server:
|
Or, it can be used to run Postgres and pass parameters to the server:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run postgres postgres --help
|
$ docker run postgres postgres --help
|
||||||
```
|
```
|
||||||
|
|
||||||
Lastly, it could also be used to start a totally different tool, such as Bash:
|
Lastly, it could also be used to start a totally different tool, such as Bash:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker run --rm -it postgres bash
|
$ docker run --rm -it postgres bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ CMD ["./app"]
|
||||||
You only need the single Dockerfile. You don't need a separate build script,
|
You only need the single Dockerfile. You don't need a separate build script,
|
||||||
either. Just run `docker build`.
|
either. Just run `docker build`.
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker build -t alexellis2/href-counter:latest .
|
$ docker build -t alexellis2/href-counter:latest .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ Dockerfile including every stage. You can specify a target build stage. The
|
||||||
following command assumes you are using the previous `Dockerfile` but stops at
|
following command assumes you are using the previous `Dockerfile` but stops at
|
||||||
the stage named `builder`:
|
the stage named `builder`:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
$ docker build --target builder -t alexellis2/href-counter:latest .
|
$ docker build --target builder -t alexellis2/href-counter:latest .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue