Skip to content

Commit d1b01e2

Browse files
author
Misty Stanley-Jones
authored
Clarify scratch image example (docker#5947)
1 parent 4b9c800 commit d1b01e2

1 file changed

Lines changed: 48 additions & 20 deletions

File tree

‎develop/develop-images/baseimages.md‎

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,56 @@ GitHub Repo:
6060

6161
## Create a simple parent image using scratch
6262

63-
You can use Docker's reserved, minimal image, `scratch`, as a starting point for building containers. Using the `scratch` "image" signals to the build process that you want the next command in the `Dockerfile` to be the first filesystem layer in your image.
64-
65-
While `scratch` appears in Docker's repository on the hub, you can't pull it, run it, or tag any image with the name `scratch`. Instead, you can refer to it in your `Dockerfile`. For example, to create a minimal container using `scratch`:
66-
67-
FROM scratch
68-
ADD hello /
69-
CMD ["/hello"]
70-
71-
Assuming you built the "hello" executable example [from the Docker GitHub example C-source code](https://github.com/docker-library/hello-world/blob/master/hello.c), and you compiled it with the `-static` flag, you can then build this Docker image using: `docker build --tag hello .`
72-
73-
> **Note**: Because Docker for Mac and Docker for Windows use a Linux VM, you must compile this code using a Linux toolchain to end up
74-
> with a Linux binary. Not to worry, you can quickly pull down a Linux image and a build environment and build within it:
75-
76-
$ docker run --rm -it -v $PWD:/build ubuntu:16.04
77-
container# apt-get update && apt-get install build-essential
78-
container# cd /build
79-
container# gcc -o hello -static -nostartfiles hello.c
80-
81-
Then you can run it (on Linux, Mac, or Windows) using: `docker run --rm hello`
63+
You can use Docker's reserved, minimal image, `scratch`, as a starting point for
64+
building containers. Using the `scratch` "image" signals to the build process
65+
that you want the next command in the `Dockerfile` to be the first filesystem
66+
layer in your image.
67+
68+
While `scratch` appears in Docker's repository on the hub, you can't pull it,
69+
run it, or tag any image with the name `scratch`. Instead, you can refer to it
70+
in your `Dockerfile`. For example, to create a minimal container using
71+
`scratch`:
72+
73+
```Dockerfile
74+
FROM scratch
75+
ADD hello /
76+
CMD ["/hello"]
77+
```
78+
79+
Assuming you built the "hello" executable example by following the instructions
80+
at
81+
[https://github.com/docker-library/hello-world/](https://github.com/docker-library/hello-world/),
82+
and you compiled it with the `-static` flag, you can build this Docker
83+
image using this `docker build` command:
84+
85+
```bash
86+
docker build --tag hello .
87+
```
88+
89+
Don't forget the `.` character at the end, which sets the build context to the
90+
current directory.
91+
92+
> **Note**: Because Docker for Mac and Docker for Windows use a Linux VM, you
93+
> you need a Linux binary, rather than a Mac or Windows binary.
94+
> You can use a Docker container to build it:
95+
>
96+
> ```bash
97+
> $ docker run --rm -it -v $PWD:/build ubuntu:16.04
98+
>
99+
> container# apt-get update && apt-get install build-essential
100+
> container# cd /build
101+
> container# gcc -o hello -static -nostartfiles hello.c
102+
> ```
103+
104+
To run your new image, use the `docker run` command:
105+
106+
```bash
107+
docker run --rm hello
108+
```
82109
83110
This example creates the hello-world image used in the tutorials.
84-
If you want to test it out, you can clone [the image repo](https://github.com/docker-library/hello-world).
111+
If you want to test it out, you can clone
112+
[the image repo](https://github.com/docker-library/hello-world).
85113

86114

87115
## More resources

0 commit comments

Comments
 (0)