Skip to content

Instantly share code, notes, and snippets.

@mick-io
Last active December 16, 2020 03:09
Show Gist options
  • Save mick-io/89f50564580b02011866646f0ff658ed to your computer and use it in GitHub Desktop.
Save mick-io/89f50564580b02011866646f0ff658ed to your computer and use it in GitHub Desktop.
docker-notes

Docker Container CLI Commands

Run a container

# Running a container
# '-d' flag: Run container in background and print container ID
# '--name string' flag: Assign a name to the container
# '-p' flag: Publish a container's port(s) to the host

docker container run -d --name [container name] \
-p [Docker host port]: [App listen port] \
[Docker Hub ID]/[Git Repo Name]:[Image Name]


# Example:
docker container run -d --name web -p 8000:8080 \
mickio/gsd:first-ctr

Run an internactive container

# '--name string' flag: Assign a name to the container
# '-i' flag: Keep STDIN open even if not attached
# '-t' flag: Allocate a pseudo-teletypewriter


docker container run -it --name [Container Name] [Imagine] [App]

docker container run -it --name test apline sh

# ctrl+P+Q to escape the container without killing it

Stop a container

docker container stop [Container ID | Container Name]

Delete a container

docker container rm [Container ID | Container Name]

Docker For Web Developers

Notes from the Pluralsight course Docker For Web Develoeprs

Dockerfile Exmaple

The Express Generator application can be created with the following script:

mkdir 
cd express-generator
npx express-geneator

Using the Express Generator application. We can containerize it with the following Dockerfile:

FROM node:latest

LABEL author="Mick Piereder"
LABEL email="[email protected]"

ENV NODE_ENV=production
ENV PORT=3000

COPY . /var/www
WORKDIR /var/www

VOLUME [ "/var/www" ]

RUN npm i

EXPOSE $PORT 

ENTRYPOINT ["npm", "start"]

Docker Image CLI Commands

Building a Docker image

# Build a Docker image
# '-t' flag: Name and optionally a tag in the 'name:tag' format
# 'dir' should be the directory where the Dockerfile is located.
docker image build -t [Docker Hub ID]/[Git Repo Name]:[Image Name] [dir]

# List your local Docker images to ensure the image was sucessfully created
docker image ls

Pushing a Docker image to a repository

# Push a Docker image to a repository
docker image push [Docker Hub ID]/[Git Repo Name]:[Image Name]

Removing local copy of image

docker image rm [Docker Hub ID]/[Git Repo Name]:[Image Name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment