Table of contents
  1. Path for ubuntu for windows
  2. Basic Docker Concepts and Terms
    1. Docker Image:
    2. Docker Container:
    3. Docker Hub:
    4. Dockerfile:
    5. Docker Compose:
  3. Basic Docker Commands
    1. version: Display Docker version.
    2. Display system-wide information.
    3. mage: Run a Docker container from an image.
    4. List running Docker containers.
    5. List all Docker containers.
    6. Stop a running container.
    7. Remove a Docker container.
    8. List Docker images.
    9. Remove a Docker image.
    10. Pull an image from a Docker registry (Docker Hub by default).
    11. Push an image to a Docker registry.
    12. Execute a command in a running container.
    13. Fetch the logs of a container.
    14. Starts one or more stopped containers.
    15. Stops one or more running containers.
    16. Build an image from a Dockerfile.
    17. Pull an image or a repository from a registry.
    18. Push an image or a repository to a registry.
    19. Exports a container’s filesystem as a tar archive.
    20. Runs a command in a run-time container.
    21. Searches the Docker Hub for images.
    22. Attaches to a running container.
    23. Creates a new image from a container’s changes.
  4. Intermediate Docker Commands
    1. Run a Docker container in detached mode.
    2. Map a port from the host to a container.
    3. Mount a volume from the host to a container.
    4. Set environment variables in a container.
    5. Return low-level information on Docker objects.
    6. Build a Docker image with a tag from a Dockerfile in the current directory.
  5. Dockerfile Commands
    1. FROM image
    2. RUN
    3. CMD
    4. ENV VAR=VALUE
    5. ADD source destination
    6. COPY source destination
    7. ENTRYPOINT
    8. LABEL
    9. EXPOSE
    10. ENTRYPOINT
    11. VOLUME
    12. USER
    13. WORKDIR
    14. ARG
    15. ONBUILD
  6. Docker Compose Commands
    1. Create and start containers.
    2. Stop and remove containers, networks, images, and volumes.
    3. Build or rebuild services.
    4. View output from containers.
    5. Restart services.
    6. Pause services.
    7. Unpause services.
    8. Start existing containers for a service.
    9. Stop running containers without removing them.
    10. CREATE DOCKER HUB IMAGE
      1. Docker Push:
      2. Creating an image for Docker Hub:
      3. Set up your environment:
      4. Create the Dockerfile:
      5. Build the image:
      6. Push the image to Docker Hub:
      7. Push the latest image to Docker Hub:
  7. Docker Compose
    1. INSTALL
      1. Download the latest version of Docker Compose:
      2. Apply executable permissions:
    2. Test Docker Compose




Path for ubuntu for windows

C:\\Users\\bpaxton\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\\rootfs

Basic Docker Concepts and Terms

Docker Image:

A lightweight, stand-alone, executable package that includes everything needed to run a piece of software.

Docker Container:

A runtime instance of a Docker image.

Docker Hub:

A cloud-based registry service where Docker users and partners create, test, store, and distribute container images.

Dockerfile:

A text document that contains all the commands a user could call on the command line to assemble an image.

Docker Compose:

A tool for defining and running multi-container Docker applications.

Basic Docker Commands

version: Display Docker version.

docker --version

Display system-wide information.

docker info

mage: Run a Docker container from an image.

docker run

List running Docker containers.

docker ps

List all Docker containers.

docker ps a

Stop a running container.

docker stop container_id

Remove a Docker container.

docker rm container_id

List Docker images.

docker images

Remove a Docker image.

docker rm image_id

Pull an image from a Docker registry (Docker Hub by default).

docker pull

Push an image to a Docker registry.

docker push

Execute a command in a running container.

docker exec

Fetch the logs of a container.

docker logs

Starts one or more stopped containers.

docker start

Stops one or more running containers.

docker stop

Build an image from a Dockerfile.

docker build

Pull an image or a repository from a registry.

docker pull

Push an image or a repository to a registry.

docker push

Exports a container’s filesystem as a tar archive.

docker export

Runs a command in a run-time container.

docker exec

Searches the Docker Hub for images.

docker search

Attaches to a running container.

docker attach

Creates a new image from a container’s changes.

docker commit

Intermediate Docker Commands

Run a Docker container in detached mode.

docker run -d image:

Map a port from the host to a container.

docker run -p host_port:container_port image

Mount a volume from the host to a container.

docker run -v host_volume:container_volume image

Set environment variables in a container.

 docker run -e VAR=VALUE image

Return low-level information on Docker objects.

 docker inspect container_id/image_id

Build a Docker image with a tag from a Dockerfile in the current directory.

 docker build -t tag .

Dockerfile Commands

FROM image

Set the base image.

RUN

Run a command.

CMD

Set a default command that will run when the container starts.

ENV VAR=VALUE

Set environment variables.

ADD source destination

Copy files from source to the container's filesystem at the destination.

COPY source destination

Copy new files or directories from source and add them to the filesystem of the container at the destination.

ENTRYPOINT

Allow you to configure a container that will run as an executable.

LABEL

Adds metadata to an image.

EXPOSE

Informs Docker that the container listens on the specified network ports at runtime.

ENTRYPOINT

Allows you to configure a container that will run as an executable.

VOLUME

Creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.

USER

Set the username (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that
follow it in the Dockerfile.

WORKDIR

Set the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD instructions that follow it in the Dockerfile.

ARG

Define a variable that users can pass at build-time to the builder with the docker build command.

ONBUILD

Adds a trigger instruction when the image is used as the base for another build.

Docker Compose Commands

Create and start containers.

docker-compose up

Stop and remove containers, networks, images, and volumes.

docker-compose down

Build or rebuild services.

docker-compose build

View output from containers.

docker-compose logs

Restart services.

docker-compose restart

Pause services.

docker-compose pause

Unpause services.

docker-compose unpause

Start existing containers for a service.

docker-compose start

Stop running containers without removing them.

docker-compose stop
docker-compose config

CREATE DOCKER HUB IMAGE

Docker Push:

docker image push <USERNAME><IMAGE_NAME>:<TAG>

Creating an image for Docker Hub:

docker image tag <IMAGE_NAME>:<TAG>

Set up your environment:

 cd docker_images

 mkdir dockerhub

 cd dockerhub

Create the Dockerfile:

vim Dockerfile

Dockerfile contents:

# Create an image for the weather-app using multi-stage build

FROM node AS build

RUN mkdir -p /var/node/

ADD src/ /var/node/

WORKDIR /var/node

RUN npm install

FROM node:alpine

ARG VERSION=V1.1

LABEL org.label-schema.version=\$VERSION

ENV NODE_ENV=\"production\"

COPY --from=build /var/node /var/node

WORKDIR /var/node

EXPOSE 3000

ENTRYPOINT \[\"./bin/www\"\]

# Git weather-app code:
git clone "https://github.com/linuxacademy/content-weather-app.git" src

# Use the Git commit hash as the image tag:
cd src
git log -1 --pretty=%H
cd ../

Build the image:

docker image build -t <USERNAME>weather-app:<HASH> --build-arg
VERSION=1.5 .

Tag the image before pushing it to Docker Hub:

docker image tag linuxacademy/weather-app:<HASH>
<USERNAME>weather-app:<HASH>

Push the image to Docker Hub:

docker login

docker images
docker tag stacksimplify/mynginx_image1:v1 stacksimplify/mynginx_image1:v1-release
docker push stacksimplify/mynginx_image1:v1-release

# Replace your docker hub account Id
docker tag <your-docker-hub-id>/mynginx_image1:v1 <your-docker-hub-id>/mynginx_image1:v1-release
docker push <your-docker-hub-id>/mynginx_image1:v1-release

Push the latest image to Docker Hub:

docker login <USERNAME>
docker image push <USERNAME>weather-app:latest

Docker Compose

INSTALL

Download the latest version of Docker Compose:

  sudo curl -L
  \"https://github.com/docker/compose/releases/download/1.23.2/docker-compose-\$(uname -s)-\$(uname -m)\" -o /usr/local/bin/docker-compose

Apply executable permissions:

sudo chmod +x /usr/local/bin/docker-compose

Test Docker Compose

docker-compose --version