!docker run -it ubuntu /bin/bash
remark: -i:interactive;
-t:tty(teletypewriter, i.e. text-only console)
In [ ]:
instead running an interactive shell, one can initiaa
In [7]:
!docker run --name daemon-dyson -d ubuntu /bin/bash -c "while true; do echo hello world;sleep 1;done"
In [8]:
!docker ps -a
In [9]:
!docker logs daemon-dyson
In [12]:
!docker logs -t --tail 10 daemon-dyson
In [ ]:
!docker logs -t -f daemon-dyson
the flag -f will keep refreshing the log file.
In [13]:
!docker top daemon-dyson
In [ ]:
showing the last three processes:
In [2]:
!docker ps -n 3
!docker attach daemon-dyson
In [8]:
!docker inspect daemon-dyson
In [19]:
%%bash
docker inspect --format="{{.State.Running}}" daemon-dyson
In [18]:
%%bash
docker inspect --format="{{.NetworkSettings.IPAddress}}" daemon-dyson
the -A flag of grep:
(-A: afterwards)
In [27]:
%%bash
docker inspect daemon-dyson |grep -A 100 "NetworkSettings"
In [28]:
%%bash
docker stop daemon-dave
docker rm daemon-dave
In [32]:
%%bash
docker ps -a
In [33]:
!docker images
In [35]:
!docker search ubuntu
In [37]:
!docker search dafu
In [40]:
%%bash
docker search busybox
In [42]:
%%bash
docker pull busybox
In [51]:
!docker history ubuntu
In [ ]:
$docker rm $(docker ps -a -q)
In [69]:
for name in ["daemon-dyson","thirsty_kirch","lonely_brahmagupta","hungry_ritchie","modest_bartik","lonely_stallman"]:
!docker rm {name}
!docker ps -a
we add some layers to the base image ubuntu:
# Version: 0.0.1
FROM ubuntu
MAINTAINER CHWENG "CHWENG@example.com"
# Avoid ERROR: invoke-rc.d: policy-rc.d denied execution of start.
#RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
RUN apt-get update
RUN apt-get install -y nginx
RUN echo 'Hi, I am in the container' \
>/var/www/html/index.html
#>/usr/share/nginx/html/index.html
CMD [ "nginx", "-g", "daemon off;" ]EXPOSE 80
In [73]:
%%bash
cd static_web/
ls
docker build -t "iiiedu/static_web" .
In [75]:
%%bash
docker images
In [76]:
%%bash
docker history iiiedu/static_web
In [77]:
%%bash
docker run -d -p 80 --name static_web iiiedu/static_web
In [80]:
%%bash
docker ps
use docker exec in order to access to an interactive terminal of the daemonized container (since if we use docker attach, we'll obtain a running terminal, which is not convenient if we'd like to do some extra things interactively.)
docker exec -it static_web /bin/bash
to look for the location of the html file generated by nginx:
root@7df500d5695b:/# find . -name "*.html"
./var/www/html/index.nginx-debian.html
./usr/share/nginx/html/index.html
./usr/share/doc/libfreetype6/ft2faq.html
./usr/share/doc/base-passwd/users-and-groups.html
./usr/share/doc/adduser/examples/adduser.local.conf.examples/skel.other/index.html
docker exec -t stat /bin/ps
PID TTY TIME CMD
35 ? 00:00:00 ps
use the flag -v(volume) to share files with the container:
docker run -it -P --name web-apache -v ~/apache2/html:/var/www/html iiiedu/apache
(a volume that is going to share data with the container will be created)
docker run -d -p 80:80 -v /tmp/www:/usr/share/nginx/html:ro nginx
In [3]:
%%bash
docker-machine env default
In [1]:
%%bash
docker run -d --name java_sock -p 9000:9000 -v $PWD/code:/javatest iiiedu/socket 9000
In [5]:
%%bash
docker search tomcat
In [4]:
%%bash
docker pull tomcat:8.0
docker run --rm tomcat:8.0 -P --name mytomcat
the flag --rm: remove the container after finishing the execusion
FROM tomcat:8.0
MAINTAINER iii education
USER root
RUN mkdir /usr/local/tomcat/webapps/jsptes
WORKDIR /usr/local/tomcat/webapps/jsptest
In [ ]:
docker run -d --name tomcat_jsp -p 8080:8080 -v $PWD/code:/usr/local/tomcat/webaps/jsptest iiiedu/tomcat
In [1]:
!vagrant --help
In [1]:
%%bash
cd ~/
vagrant box add iiiedu/trusty64 ubuntu-trusty64.box
In [2]:
!vagrant box list
In [2]:
%%bash
cd ~/
mkdir demo
cd demo
vagrant init iiiedu/trusty64
In [4]:
%%bash
cat ~/demo/Vagrantfile
In [5]:
%%bash
cd ~/demo
vagrant up
1. use box add to give vagrant an image (xxx.box) and give it a tag name, e.g. ubuntu/trusty64
2. vagrant init ubuntu/trusty64 (will create the file Vagrantfile)
3. vagrant up (set-up the guest node according to the Vagrantfile and then turn on the guest node)
4. vagrant ssh (login to the guest node)
I was trying to find the folder which contains motd(message of the day) settings. This is done by using the forgotten "find" command:
vagrant@vagrant-ubuntu-trusty-64:~$ sudo find / -type d -name "*motd*"
/etc/update-motd.d
check the file system and the harddisk:
root@vagrant-ubuntu-trusty-64:/vagrant# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
4 heads, 32 sectors/track, 655360 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00021928
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 83886079 41942016 83 Linux
root@vagrant-ubuntu-trusty-64:/vagrant# df -h
Filesystem Size Used Avail Use% Mounted on
udev 241M 12K 241M 1% /dev
tmpfs 49M 344K 49M 1% /run
/dev/sda1 40G 1.4G 37G 4% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 245M 0 245M 0% /run/shm
none 100M 0 100M 0% /run/user
vagrant 201G 124G 77G 62% /vagrant
Indeed, the mounted mount point /vagrant is the directory that is shared in between the host and the guest.
Remark: use hostnamectl to modify the host name when necessary. I am not going to do this.
In [ ]:
%%bash
cd ~/hadoop_base
vagrant up
In [4]:
%%bash
cd ~/hadoop_base
vagrant package --output hadoop_base.box
In [5]:
%%bash
cd ~/hadoop_base
vagrant box add iiiedu/hadoop_base hadoop_base.box
In [8]:
%%bash
vagrant box list
In [9]:
%%bash
cd ~/
mkdir hadoop_node
cd hadoop_node
vagrant init iiiedu/hadoop_base
In [10]:
%%bash
cd ~/hadoop_node
vagrant up
In [ ]:
%%bash
cd ~/hadoop_cluster
vagrant package master --output master.box
vagrant package slave1 --output slave1.box
vagrant package slave2 --output slave2.box
vagrant package slave3 --output slave3.box
vagrant package slave4 --output slave4.box
vagrant package slave5 --output slave5.box
In [ ]: