DevOps Classroom notes 26/May/2026

USER

  • In linux machines, root user has full permissions,
  • By default when you build image the user is going to root.
  • Example
FROM alpine:3
CMD ["sleep", "1d"]
  • docker exec command can run a command in a running container
docker exec test whoami
docker exec -it test1 /bin/sh
  • It is recommended to run you application as a normal user
  • As part of your docker image building create a user and switch to that user
  • Dockerfile
FROM alpine:3
RUN adduser -D -h /app appuser
USER appuser
CMD ["sleep", "1d"]

WORKDIR

  • WORKDIR instruction make a particular folder your current working directory
FROM alpine:3
RUN adduser -D -h /app appuser
USER appuser
WORKDIR /app
CMD ["sleep", "1d"]

Running docker contianers

  • Playing with docker commands
  • Figure out aliases dont memorize
docker images
docker image ls
docker ps
docker container ls
  • A container can be run in two modes
    • attached:
      • This is default
    • background (detached)
  • To run a docker command all we need to do is
docker run <image>
  • Detached mode
docker run -d <image>
  • When we create a container, each container gets a
    • unique id
    • unique name (if the name is not provided, docker generates a name)
  • To provide name
docker run -d --name <name> <image>

  • Name conflicts apply, two containers having same name
  • A container might have an application which is running on some port, we use portforwording for that
docker run -d  -p 18000:80 --name <name> <image>

  • To ensure we have dynamic portforwarding (When we have EXPOSE instruction)
docker run -d  -P --name <name> <image>
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%