systemctl start docker
gpasswd -a $USER docker
sudo usermod -aG docker $USER
newgrp docker
# Run ubuntu without exiting
docker run -p 8091:80 -idt --name ub1 ubuntu
docker run -p 8092:80 -idt --name ub2 ubuntu
docker run -p 8095:80 -idt --name ub3 --network other-network ubuntu
FROM ubuntu:latest
RUN apt update && apt install openssh-server sudo -y && apt-get nmap
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test
RUN echo 'test:test' | chpasswd
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
docker build -t ub .
docker run -p 8091:22 -idt --name ub1 ub
docker run -p 8092:80 -idt --name ub2 ub
# Get IP Addressess
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ub1
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ub2
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ub3
# Check Connectivty
docker exec -t ub1 bash -c "ls"
docker network create --driver bridge --subnet 182.18.0.1/24 --gateway 182.18.0.1 other-network
docker run -p 8095:80 -idt --name ub3 --network other-network ub
#ANSIBLE TEST
ssh test@172.17.0.3
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub test@172.17.0.3
docker network ls
docker inspect cont_name or ID
docker network inspect bridge, host, none
# ex:
docker run --name alpine-2 --network=none alpine
# Create a new network named wp-mysql-network using the bridge driver.
# Allocate subnet 182.18.0.1/24.
# Configure Gateway 182.18.0.1
docker network create --driver bridge --subnet 182.18.0.1/24 --gateway 182.18.0.1 wp-mysql-network
# Deploy a mysql database using the mysql:5.6 image and name it mysql-db.
# Attach it to the newly created network wp-mysql-network
docker run -d -e MYSQL_ROOT_PASSWORD=db_pass123 --name mysql-db --network wp-mysql-network mysql:5.6
# Deploy a web application named webapp, using image kodekloud/simple-webapp-mysql.
# Expose port to 38080 on the host.
# The application takes an environment variable DB_Host that has the hostname of the mysql database.
# Make sure to attach it to the newly created network wp-mysql-network
docker run --network=wp-mysql-network -e DB_Host=mysql-db -e DB_Password=db_pass123 -p 38080:8080 --name webapp --link mysql-db:mysql-db -d kodekloud/simple-webapp-mysql