Tag: docker build

  • Build a docker container with Apache

    To create a docker container with Apache, create a Dockerfile

    mkdir my-app
    cd my-app
    vi Dockerfile
    

    Paste following content into the Dockerfile

    from ubuntu:20.04
    
    ARG DEBIAN_FRONTEND=noninteractive
    
    RUN apt-get update && apt-get install -y apache2
    
    RUN echo 'Hello World!' > /var/www/html/index.html
    
    RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
     echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
     echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \ 
     echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \ 
     chmod 755 /root/run_apache.sh
    
    EXPOSE 80
    
    CMD /root/run_apache.sh
    

    Now build an image with command

    docker build -t sevrerok/okapache:1.0 .
    

    Once image is build, you can see it using docker images command

    [root@instance-20210426-0136 my-app]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    sevrerok/okapache   1.2                 c3832b03b548        8 minutes ago       214MB
    sevrerok/okapache   1.1                 d1a86f0eb69a        37 minutes ago      214MB
    ubuntu              20.04               7e0aa2d69a15        2 days ago          72.7MB
    sevrerok/okapache   1.0                 7e0aa2d69a15        2 days ago          72.7MB
    [root@instance-20210426-0136 my-app]# 
    

    To start a container with the image, run

    docker container run -d -p 80:80 sevrerok/okapache:1.0
    

    See docker build

  • Docker Build

    Build a docker container with Apache

    docker build command is used to create a docker image from Dockerfile.

    To create an image, first lets create a working directory and change to the directory.

    mkdir ~/my-docker-image
    cd ~/my-docker-image
    

    Create a file with name Dockerfile

    vi Dockerfile
    

    Put following content in it

    FROM ubuntu:18.04
    
    RUN apt update && apt upgrade -y
    
    CMD ["/bin/bash"]
    

    Now build the docker image with

    docker build -t my-ubuntu .
    

    This will create a docker image with name “my-ubuntu”.

    To run this, we need to create a container using this image, this can be done with command

    docker run -ti my-ubuntu
    

    Here i used -ti as we need to run interactively using terminal, this is because our the command we set to start is “/bin/bash” in the Dockerfile.

    Docker