Last active
August 29, 2015 14:05
-
-
Save ountzza/985637fa7afa1d7f6d44 to your computer and use it in GitHub Desktop.
Docker training
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://192.168.100.7:81 | |
MAC OS X | |
boot2docker init | |
boot2docker up | |
boot2docker ssh | |
Edit Hosts files | |
sudo vi /etc/hosts | |
192.168.100.7 r | |
Docker Operation Command | |
docker search ubuntu | |
# https://registry.hub.docker.com/ | |
docker pull r:80/centos | |
docker images | |
docker pull r:80/ubuntu:14.04 | |
docker pull r:80/ubuntu:latest | |
docker run r:80/ubuntu echo “Hello World” | |
docker run r:80/ubuntu ls -l | |
docker run -i -t r:80/ubuntu /bin/bash | |
whoami | |
hostname | |
cat /etc/*release* | |
exit | |
docker ps | |
docker ps -a | |
docker rm elegant_pike | |
docker rm fabc1e7f8816 | |
docker rm 455 822 | |
Build first Docker Image | |
docker run -i -t ubuntu /bin/bash | |
vim | |
echo 'Acquire::http::Proxy "http://192.168.100.7:3142";' > /etc/apt/apt.conf.d/11proxy | |
apt-get update && apt-get install -y vim | |
touch vim-installed | |
exit | |
docker ps -a | |
docker commit [cid] ubuntu-vim | |
docker images | |
docker run -i -t ubuntu-vim /bin/bash | |
ls -l vim-installed | |
Docker Registry Operation | |
Register your account at https://hub.docker.com | |
You can pull without logging-in | |
docker login | |
docker push ubuntu-vim | |
docker tag ubuntu-vim username/ubuntu-vim | |
docker images | |
docker push username/ubuntu-vim | |
docker pull xxx/ubuntu-vim | |
Expose Port | |
ifconfig eth1 | |
docker run -i -t -p 80:80 r:80/ubuntu /bin/bash | |
echo 'Acquire::http::Proxy "http://192.168.100.7:3142";' > /etc/apt/apt.conf.d/11proxy | |
apt-get update && apt-get install apache2 | |
service apache2 start | |
Go to browser: http://ipaddress | |
exit | |
*Commit your apache2 container as ubuntu-apache2 with tag 14.04 and latest | |
*Clear your stopped containers | |
Try Daemon Mode | |
docker run ubuntu-apache2 | |
docker run -d ubuntu-apache2 service apache2 start | |
docker run -d ubuntu-apache2 apachectl -DFOREGROUND | |
docker run -d -p 80:80 ubuntu-apache2 apachectl -DFOREGROUND | |
docker run -d -p 8880:80 ubuntu-apache2 apachectl -DFOREGROUND | |
docker run -d -p 80 ubuntu-apache2 apachectl -DFOREGROUND | |
Using Docker Image to build private Docker registry | |
docker run -d -p 5000:5000 r:80/registry | |
docker run -d -p 8080:8080 r:80/docker-registry-ui | |
Practice | |
Create ready-to-run Docker image that can SSH to with these commands | |
apt-get update && apt-get install -y openssh-server | |
sed -i 's/required pam_loginuid.so/optional pam_loginuid.so/g' /etc/pam.d/sshd | |
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config | |
mkdir /var/run/sshd | |
passwd #to set ssh password for root | |
Run openssh-server foreground with command | |
/usr/sbin/sshd -D | |
Name Docker image as your-private-registry-ip:5000/ubuntu-ssh with tag 20140830 and latest and push it | |
Try to run container with ssh port 2222 and ssh to container | |
ssh -p 2222 root@localhost | |
Dockerfile | |
FROM r:80ubuntu | |
RUN apt-get update | |
RUN apt-get install -y openssh-server | |
RUN sed -i 's/required pam_loginuid.so/optional pam_loginuid.so/g' /etc/pam.d/sshd | |
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config | |
RUN mkdir /var/run/sshd | |
RUN echo "root:test1234" | chpasswd | |
CMD /usr/sbin/sshd -D | |
EXPOSE 22 | |
############################################# | |
FROM ubuntu | |
RUN apt-get update && apt-get install -y nginx | |
RUN echo “daemon off;” >> /etc/nginx/nginx.conf | |
ADD default /etc/nginx/sites-available/default | |
CMD /usr/sbin/nginx -c /etc/nginx/nginx.conf | |
EXPOSE 80 | |
############################################# | |
vi default | |
############################################# | |
server { | |
listen 80; | |
location / { | |
proxy_pass http://ipaddress:8080; | |
proxy_read_timeout 900; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment