docker commands | Delete danglings images in cmd | | Search

To build Docker images, use the provided commands, such as docker build -t <image_name>:<tag> --target <stage>, to create images with specific tags. To push Docker images to a registry, use the docker push command with the image name and tag, such as docker push briancullinan/quake3e:<tag>.

Cell 9

docker build -t briancullinan/quake3e:build-tools --target build-tools .
docker build -t briancullinan/quake3e:build-latest --no-cache --target build-latest .
docker build -t briancullinan/quake3e:build-ded --target build-ded .
docker build -t briancullinan/quake3e:build-js --target build-js .

docker build -t briancullinan/quake3e:serve-tools --no-cache --target serve-tools .
docker build -t briancullinan/quake3e:serve-content --target serve-content .
docker build -t briancullinan/quake3e:serve-quake3e --target serve-quake3e .
docker build -t briancullinan/quake3e:serve-both --target serve-both .
docker build -t briancullinan/quake3e:repack --target repack .
docker build -t briancullinan/quake3e:latest --target latest .

docker run -ti -v /Applications/ioquake3/baseq3:/home/baseq3 --name baseq3 briancullinan/quake3e:repack
docker commit baseq3
docker tag baseq3 briancullinan/quake3e:baseq3

docker build -t briancullinan/quake3e:full --target full .

docker push briancullinan/quake3e:build-tools
docker push briancullinan/quake3e:build-latest
docker push briancullinan/quake3e:build-js
docker push briancullinan/quake3e:build-content

docker push briancullinan/quake3e:serve-tools
docker push briancullinan/quake3e:serve-content
docker push briancullinan/quake3e:serve-quake3e
docker push briancullinan/quake3e:serve-both
docker push briancullinan/quake3e:repack
docker push briancullinan/quake3e:latest
docker push briancullinan/quake3e:baseq3
docker push briancullinan/quake3e:full

What the code could have been:

#!/bin/bash

IMAGE_NAME="briancullinan/quake3e"
TAGS=("build-tools" "build-latest" "build-js" "build-ded" "serve-tools" "serve-content" "serve-quake3e" "serve-both" "repack" "latest" "baseq3" "full")
TARGETS=("build-tools" "build-latest" "build-js" "build-ded" "serve-tools" "serve-content" "serve-quake3e" "serve-both" "repack" "latest" "build-latest" "full")

VOLUME_MOUNT="/Applications/ioquake3/baseq3:/home/baseq3"

for i in "${!TAGS[@]}"; do
  build_target=${TARGETS[$i]}
  image_tag="${IMAGE_NAME}:${TAGS[$i]}"

  # Build the image
  echo "Building image ${image_tag} with target ${build_target}"
  docker build -t "${image_tag}" --target "${build_target}".

  # Push the image
  echo "Pushing image ${image_tag}"
  docker push "${image_tag}"
done

# Run and commit the container
echo "Running container baseq3 with volume mount ${VOLUME_MOUNT}"
docker run -ti -v ${VOLUME_MOUNT} --name baseq3 ${IMAGE_NAME}:repack
docker commit baseq3
docker tag baseq3 ${IMAGE_NAME}:baseq3

# Build the full image
echo "Building image ${IMAGE_NAME}:full with target full"
docker build -t ${IMAGE_NAME}:full --target full.
docker push ${IMAGE_NAME}:full

Docker Build and Push Commands

Build Commands

These commands build and create Docker images with specific tags.

  1. Build Tools Image

docker build -t briancullinan/quake3e:build-tools --target build-tools.

   * Targets the `build-tools` stage in the Dockerfile.

2. **Build Latest Image**
   ```bash
docker build -t briancullinan/quake3e:build-latest --no-cache --target build-latest.
  1. Build Dedicated Server Image

docker build -t briancullinan/quake3e:build-ded --target build-ded.

   * Targets the `build-ded` stage in the Dockerfile.

4. **Build JavaScript Image**
   ```bash
docker build -t briancullinan/quake3e:build-js --target build-js.
  1. Serve Tools Image

docker build -t briancullinan/quake3e:serve-tools --no-cache --target serve-tools.

   * Targets the `serve-tools` stage in the Dockerfile.
   * Does not use the cache for this build.

6. **Serve Content Image**
   ```bash
docker build -t briancullinan/quake3e:serve-content --target serve-content.
  1. Serve Both Image

docker build -t briancullinan/quake3e:serve-both --target serve-both.

   * Targets the `serve-both` stage in the Dockerfile.

8. **Repack Image**
   ```bash
docker build -t briancullinan/quake3e:repack --target repack.
  1. Latest Image

docker build -t briancullinan/quake3e:latest --target latest.

   * Targets the `latest` stage in the Dockerfile.

10. **Full Image**
    ```bash
docker build -t briancullinan/quake3e:full --target full.
* Targets the `full` stage in the Dockerfile.

Run and Tag Commands

These commands run and tag a Docker container.

  1. Run Repack Container

docker run -ti -v /Applications/ioquake3/baseq3:/home/baseq3 --name baseq3 briancullinan/quake3e:repack

   * Runs a container from the `repack` image.
   * Maps the host directory `/Applications/ioquake3/baseq3` to the container directory `/home/baseq3`.
   * Assigns the container name `baseq3`.

2. **Commit Container**
   ```bash
docker commit baseq3
  1. Tag Container

docker tag baseq3 briancullinan/quake3e:baseq3

   * Tags the `baseq3` container with the `briancullinan/quake3e:baseq3` image.

### Push Commands

These commands push Docker images to a registry.

1. **Push Build Tools Image**
   ```bash
docker push briancullinan/quake3e:build-tools
  1. Push Build Latest Image

docker push briancullinan/quake3e:build-latest

   * Pushes the `build-latest` image to the registry.

3. **Push Build JavaScript Image**
   ```bash
docker push briancullinan/quake3e:build-js
  1. Push Build Content Image

docker push briancullinan/quake3e:build-content

   * Pushes the `build-content` image to the registry.

5. **Push Serve Tools Image**
   ```bash
docker push briancullinan/quake3e:serve-tools
  1. Push Serve Content Image

docker push briancullinan/quake3e:serve-content

   * Pushes the `serve-content` image to the registry.

7. **Push Serve Quake3e Image**
   ```bash
docker push briancullinan/quake3e:serve-quake3e
  1. Push Serve Both Image

docker push briancullinan/quake3e:serve-both

   * Pushes the `serve-both` image to the registry.

9. **Push Repack Image**
   ```bash
docker push briancullinan/quake3e:repack
  1. Push Latest Image

docker push briancullinan/quake3e:latest

    * Pushes the `latest` image to the registry.

11. **Push Baseq3 Image**
    ```bash
docker push briancullinan/quake3e:baseq3
* Pushes the `baseq3` image to the registry.
  1. Push Full Image

docker push briancullinan/quake3e:full

    * Pushes the `full` image to the registry.