DevOps Classroomnotes 05/Feb/2022

Activity 6

  • Understanding ARG:
  • ARG instruction helps in passing arguments while building the image. This ARG has no validity once the image is built i.e. this ARG will not be available in the Container
FROM alpine
ARG MESSAGE=hello
ENV GREETINGS=Docker
RUN echo $MESSAGE && echo $GREETINGS
CMD set
  • Lets build the image with different variations (with arguments passed and not passed)
    Preview
    Preview

Activity 7:

  • Other Instructions
  • WORKDIR: This instruction sets the default working directory
  • USER: This instructions sets the USER to use when running the container
  • When we create a container generally the default user is root and the default working directory is / (root directory)
    Preview
  • Lets create a dockerfile
FROM ubuntu:20.04
ARG user=qtdevops
ARG group=qtdevops
ARG uid=1000
ARG gid=1000
ENV USER_HOME_DIR /home/qtdevops
RUN groupadd -g ${gid} ${group} \
    && useradd -d "$USER_HOME_DIR" -u ${uid} -g ${gid} -m -s /bin/bash ${user}
USER ${user}
WORKDIR ${USER_HOME_DIR}
CMD ["echo", "helloworld"]

  • Build the image and then create a container in the interactive mode to inspect
    Preview

Exercise: Try to Containerize nop commerce

FROM mcr.microsoft.com/dotnet/aspnet:3.1-focal
RUN apt update && apt install unzip && mkdir /usr/share/nop
WORKDIR /usr/share/nop
ADD https://github.com/nopSolutions/nopCommerce/releases/download/release-4.50.0/nopCommerce_4.50.0_NoSource_linux_x64.zip /usr/share/nop/nopCommerce_4.50.0_NoSource_linux_x64.zip
RUN unzip nopCommerce_4.50.0_NoSource_linux_x64.zip
EXPOSE 80
CMD ["/usr/bin/dotnet", "/usr/share/nop/Nop.Web.dll"]
  • Try building the docker image and run the container
docker container run -d -P nop

Preview
* Now access the application
Preview

  • Once we are done building our images we can push them to registries.
  • Lets push nop commerce to a docker hub
  • To push you need to login
    Preview
  • The images in docker hub are stored in repositories with each repository having a name <acount-username>/<image-name>
  • To push nop commerce i need to have my image in the form of shaikkhajaibrahim/nop
  • Now lets tag nop to the new naming convention docker image tag nop shaikkhajaibrahim/nop:1.0
  • Now push docker image push shaikkhajaibrahim/nop:1.0
  • Refer Here
  • Now lets try to push the image to AWS Elastic Container Registry
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
  • Refer Here to install AWS CLI
  • Now create an IAM User Refer Here
  • Follow the instructions to push the image
    Preview
  • Now view the repository in aws
    Preview
  • Now lets try to creat an Azure Container registry and push the nop image to it
    Preview
    Preview
    Preview
  • Continue the wizard to create the container registry
  • Once the acr is created
    Preview
  • We need to login into the registry & for that we need to install azure cli Refer Here
  • Refer Here for official docs
  • Login into azure from cli using az login
    Preview

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner