07/09/20 Notes
Docker
Build your custom image using a docker file:
Create a Dockfile file. There is a sample one below.
From the same directory run - docker build -t image-name .
Docker Image Commands:
View images - docker image ls
Delete an image - docker image rm imagename
Docker Container Commands:
Show running containers - docker ps
Show all containers, ie stopped as weel - docker ps -a
Start a container - docker start containername
Stop a container - docker stop containername
Delete a continer - docker rm containername
Show containers logs, useful for troubleshooting - docker logs containername
Cleanup broken containers and images - docker system prune
Run a bash shell in a docker image - docker run -it image-name /bin/bash
Run a bash shell in a docker container - docker exec -it tayicseua /bin/bash
How I run my container. if I don't do sleep infinity the container stops:
docker run -d -t -p 80:80 --name tayicseua website-image bash -c "service apache2 start && sleep infinity"
Sample Dockerfile:
# Download Ubuntu base OS
FROM ubuntu:20.04
# LABEL about this custom image
LABEL maintainer="username@gmail.com"
LABEL version="1.0"
LABEL description="Runs my website."
# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive
# Update Ubuntu Software repository
RUN apt-get update -y && apt-get upgrade -y
# Download websites and apache config
RUN apt-get install git -y && \
mkdir website && \
cd website && \
git init && \
git config user.email "username@gmail.com" && \
git config user.name "username" && \
git pull https://username:password@github.com/username/website.git master && \
git pull https://username:password@github.com/username/apache-config.git master --allow-unrelated-histories
# Install apache and required module
RUN apt-get install apache2 -y
RUN a2enmod rewrite
# Replace apache config file
RUN mv /website/apache2.conf /etc/apache2/
RUN chown root:root /etc/apache2/apache2.conf
RUN chmod 644 /etc/apache2/apache2.conf
# Move websites into apache web directory
RUN mv /website/ /var/www/html/
RUN chown -R www-data:www-data /var/www/html
# Listen on port 80
EXPOSE 80