# 🐳 DOCKER CONCEPTS
---
## Installation Commands
In Ubuntu 16.04 or any latest version, Docker installation commands:
```
bash
sudo apt-get -f install
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
sudo apt-get update
apt-cache search docker-ce
sudo apt-get install docker-ce
Sample output:
docker-ce - Docker: the open-source application container engine
Docker Container Commands
Docker container is a running instance of an image. A container combined only libraries and settings required to make the application work. It is a lightweight and portable encapsulated environment for an application.
Run Docker Container:
bash
docker run hello-world
docker run -it centos
docker ps
docker ps -a
docker inspect <containerid>
docker stop <containerid>
docker rm <containerid>
Docker Images
An image is an inert, immutable file that’s essentially a snapshot of a container.
bash
docker images
docker pull centos
docker rmi centos
Docker Data Volumes
In Docker, data volumes are useful for managing data with Docker containers and host machines.
Create Data Volume Container
bash
docker create -v /data --name data_container centos
Use Data Volume in New Container
bash
docker run -it --volumes-from data_container centos /bin/bash
cd /data
echo "Hello Docker" > file.txt
Verify Files on Data Volume
bash
docker run -it --volumes-from data_container centos /bin/bash
Share Host Volume with Container
bash
docker run -it -v /var/www:/data centos
Working with Dockerfile
bash
docker build -t image_name .
docker build -t image_name -f /path/to/Dockerfile .
Dockerfile Directives
dockerfile
FROM ubuntu
LABEL maintainer="kiran"
LABEL vendor="org"
LABEL com.example.version="0.0.1"
RUN apt-get update && apt-get install -y \
automake \
build-essential \
curl
COPY html/* /var/www/html/
COPY *.conf /etc/apache2/sites-available/
WORKDIR /opt
CMD ["apachectl", "-D", "FOREGROUND"]
EXPOSE 80
EXPOSE 443
ENV PATH=$PATH:/usr/local/pgsql/bin/ \
PG_MAJOR=9.6.0
VOLUME ["/data"]
Manage Ports in Docker
bash
docker run -p 8080:80 nginx
Docker POCs
Running MySQL as Docker
bash
docker pull mysql/mysql-server
docker pull mysql/mysql-server:5.5
docker run --name=mysql1 -d mysql/mysql-server
docker run --name=mysql1 -d mysql/mysql-server:5.5
docker logs mysql1
docker run --name=mysql1 -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server
docker run --name=mysql1 -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server:5.5
docker logs mysql1 2>&1 | grep GENERATED
docker exec -it mysql1 mysql -u root -p
docker ps -a
sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin@123';
CREATE USER 'newUser'@'%' IDENTIFIED BY 'newPass123';
ALTER USER 'newUser'@'%' IDENTIFIED WITH mysql_native_password BY 'newPass123';
GRANT ALL PRIVILEGES ON *.* TO 'newUser'@'%' WITH GRANT OPTION;
Run Tomcat as Docker
bash
docker run -it --rm tomcat:8.0
docker run -it --rm -p 8888:8080 tomcat:8.0
Dockerfile for WAR:
dockerfile
FROM tomcat:8.0.43-jre8
ADD webdemodocker.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD chmod +x /usr/local/tomcat/bin/catalina.sh
CMD ["catalina.sh", "run"]
bash
sudo docker build -t webdemo .
sudo docker run -i -t -d -p 8080:8080 webdemo
Dockerfile for Nginx
dockerfile
FROM nginx
COPY index.html /usr/share/nginx/html
index.html:
This is hello world to Nginx
bash
docker build -t mynginx .
docker run -it -p 8080:80 mynginx
docker run -it -p 8081:80 mynginx
Spring Boot Dockerfile
dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} springbootapp.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","springbootapp.jar"]
EXPOSE 8080
bash
sudo docker build -t myspringbootapp --build-arg JAR_FILE="springbootapp.jar" .
Top comments (0)