Skip to content

Commit

Permalink
Vault backup: 2023-10-17 22:47:41
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Wong committed Oct 17, 2023
1 parent 1713a0d commit 8727595
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#course_datacamp-docker #docker

- All images used to create containers so far have been provided to us. In reality, we will be working with containers we created ourselves, or have downloaded from the community.
- Summary of covered commands:

| Command | Usage |
| ------------------------------------------- | --------------------------------------------------- |
| `docker pull <image-name>` | Pull an image from Docker Hub |
| `docker pull <image-name>:<version-number>` | Pull an image from Docker Hub of a specific version |
| `docker images` | List all installed images |
| `docker image rm <image-name>` | Remove a specific installed image |
| `docker image prune -a` | Prune all unused and dangling images |
| `docker container prune` | Remove all stopped containers |
## Docker Hub

- Docker Hub is the main registry of community-made Docker images, you are almost guaranteed to find a Docker image for any common use-case.
Expand All @@ -13,6 +22,21 @@
docker pull <image-name>
docker pull <image-name>:<version-number>
```

## Listing images

- List the images you've downloaded with `docker images`. This also tells us when the image was created, what size it is on disk, and the image's unique ID.
- Since images take up space, we should remove any that we're not using. We can do this with `docker image rm <image-name>`.
- Since a container is a running image, if we have any containers running off that image we will get an error message. This message tells us the ID of the containers we would need to stop. We can then use `docker container rm <container-id>` to [[5 DK Working with Docker containers#Cleaning up containers|remove them]].
- It is common to have multiple containers running off a single image. It might be easier to remove all stopped containers, which we can do with `docker container prune`.

![[Pasted image 20231017212110.png]]

- We can then remove all unused images with `docker image prune -a`, the `-a` flag stands for all so that the command removes all unused images, not just dangling ones.
- Dangling images are images that no longer have a name since their name was reused for another image. This frequently occurs when we iteratively work on a single image, creating new versions of it - each of which takes the image name.

```shell
docker images
docker image rm <image-name>
docker container prune
docker image prune -a
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#course_datacamp-docker #docker

- Summary of covered commands:

| Command | Usage |
| ------------------------------------------- | --------------------------------------------------- |
| `docker pull <private-registry-url>/<image-name>:<ver>` | Pull an image from a private registry |
| `docker tag <image-name>:<ver> <private-registry-url>/<image-name>:<ver>` | Rename an image for pushing to a private registry |
| `docker image push <image-name>` | Push an image to a registry |
| `docker login <private-registry-url>` | Authenticate with a private registry
| `docker save -o <file-name>.tar <image-name>` | Save an image to a local file |
| `docker load -i <file-name>.tar` | Load an image from a local file |
## Private registries

- Images are distributed through the Docker Hub but images can be hosted privately in private registry servers as well. You can tell that an image is from a private registry as the name will start with the URL of the registry.
- You pull these the same way as you pull any other image.

```shell
docker pull <private-registry-url>/<image-name>:<ver>
```

## Pushing to a registry

- To push an image to a registry run `docker image push <image-name>`. To direct it to a private registry, we need to rename the image and prepend the URL of the private repository with `docker tag`. We can then run `docker image push <new-image-name>`.

```shell
docker image push <image-name>
docker tag <image-name>:<ver> <private-registry-url>/<image-name>:<ver>
```

## Authenticating with a private registry

- Docker Hub images can be pulled without authentication, but private registries may be set up to require it. We can do this with `docker login <private-registry-url>`.

## Docker images as files

- If we want to pass an image around to only a small number of people, we can save it as a file with `docker save`. You can then load it with `docker load`.

```shell
docker save -o <file-name>.tar <image-name>
docker load -i <file-name>.tar
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8727595

Please sign in to comment.