You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/get-started/workshop/05_persisting_data.md
+16-22Lines changed: 16 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,43 +21,37 @@ changes won't be seen in another container, even if they're using the same image
21
21
22
22
### See this in practice
23
23
24
-
To see this in action, you're going to start two containers. In one container, you'll create a file. In the other container, you'll verify the file exists.
25
-
What you'll see is that the file created in one container isn't available in another.
24
+
To see this in action, you're going to start two containers. In one container,
25
+
you'll create a file. In the other container, you'll check whether that same
26
+
file exists.
26
27
27
-
1. Start an Alpine container and access its shell.
28
+
1. Start an Alpine container and create a new file in it.
28
29
29
30
```console
30
-
$ docker run -ti --name=mytest alpine
31
+
$ docker run --rm alpine touch greeting.txt
31
32
```
32
33
33
-
2. In the container, create a `greeting.txt` file with `hello` inside.
34
+
> [!TIP]
35
+
> Any commands you specify after the image name (in this case, `alpine`)
36
+
> are executed inside the container. In this case, the command `touch
37
+
> greeting.txt` puts a file named `greeting.txt` on the container's filesystem.
34
38
35
-
```console
36
-
/ # echo "hello" > greeting.txt
37
-
```
38
-
39
-
3. Exit the container.
40
-
41
-
```console
42
-
/ # exit
43
-
```
44
-
45
-
4. Run a new Alpine container and use the `cat` command to verify that the
46
-
file does not exist.
39
+
2. Run a new Alpine container and use the `stat` command to check whether the file exists.
47
40
48
41
```console
49
-
$ docker run alpine cat greeting.txt
42
+
$ docker run --rm alpine stat greeting.txt
50
43
```
51
44
52
45
You should see output similar to the following that indicates the file does not exist in the new container.
53
46
54
47
```console
55
-
cat: can't open 'greeting.txt': No such file or directory
48
+
stat: can't stat 'greeting.txt': No such file or directory
56
49
```
57
50
58
-
5. Go ahead and remove the containers using `docker ps --all` to get the IDs,
59
-
and then `docker rm -f <container-id>` to remove the containers.
60
-
51
+
The `greeting.txt` file created by the first container did not exist in the
52
+
second container. That is because the writeable "top layer" of each container
53
+
is isolated. Even though both containers shared the same underlying layers that
54
+
make up the base image, the writable layer is unique to each container.
0 commit comments