docker pull mongo
default search from docker hub
docker pull mongo:3.0
docker pull mhart/alpine-node
docker images
docker rmi mongo
docker rmi mongo:3.0
docker rmi [IMAGE ID]
docker run mongo
docker run mongo:3.0
docker run -d mongo
docker ps
docker stop [container ID]
docker ps -a
docker start [container ID]
docker stop [container ID]
docker rm [container ID]
docker run -d nginx
-d
run at background
docker ps
docker run --rm nginx nginx -h
--rm
automatically removed after container exited
docker run --rm debian hostname >> /tmp/containers
crontab -e
* * * * * /usr/local/bin/docker run --rm debian hostname >> /tmp/containers
tail -f /tmp/containers
persisted data in one or more containers
docker volume create --name webdata
docker run -d --name web1 -v webdata:/usr/share/nginx/html -p 8000:80 nginx
-d
run at background
-v
volume
-p
PORT
curl localhost:8000
docker exec web1 bash -c 'echo "foo" > /usr/share/nginx/html/index.html'
exec bash in web1 container: rewrite the html index file
curl localhost:8000
// foo
docker stop web1
docker rm web1
docker ps -a
container is removed
docker run -d --name web1 -v webdata:/usr/share/nginx/html -p 8000:80 nginx
curl localhost:8000
// foo
docker run -d --name web1 -v webdata:/usr/share/nginx/html -p 8000:80 nginx
docker run -d --name web2 -v webdata:/usr/share/nginx/html -p 8001:80 nginx
multiple container mount same volume
curl localhost:8000
// foo
curl localhost:8001
// foo
docker exec web1 bash -c 'echo "bar" > /usr/share/nginx/html/index.html'
curl localhost:8000
// bar
curl localhost:8001
// bar
Changes in volume, influence all container
docker inspect -f '{{ .Mounts }}' web1
docker volume inspect webdata
docker volume ls
# need remove all container mount this volume
docker stop web1 web2 && docker rm web1 web2
docker volume rm webdata
docker ps -a
# prune all unused container
docker container prune
docker images
# prune all image without attach a container
docker image prune
# prune system
# all stopped containers
# all volumes not used by at least one container
# all networks not used by at least one container
# all dangling images
docker system prune
# remove not only dangled images, but all unused images as well
docker system prune -a
// Load the http module to create an HTTP server
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests
var server = http.createServer(function (request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Hello, World\n");
});
// Listen on Port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log('Server running at http://127.0.0.1:8000');
FROM mhart/alpine-node
COPY index.js .
EXPOSE 8000
CMD node index.js
docker build -t myserver .
-t
for tag
docker images
docker run -p 8000:8000 myserver
-p
for PORT
visit localhost:8000
mkdir nodejs nginx
// Load the http module to create an HTTP server
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests
var server = http.createServer(function (request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Welcome to Node.js!\n");
});
// Listen on Port 3000, IP defaults to 127.0.0.1
server.listen(3000);
// Put a friendly message on the terminal
console.log('Server running at http://127.0.0.1:3000');
FROM mhart/alpine-node
COPY index.js .
EXPOSE 3000
CMD node index.js
Now, build and run
docker build -t foo/node .
docker run -d -p 3000:3000 --name node-app foo/node
-d
run at background
-p
PORT
--name
name
docker run --rm -p 8000:80 nginx
--rm
Automatically remove the container when it exits
-p
PORT
server {
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote-addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $schema;
proxy_pass http://app:3000;
}
}
FROM nginx
COPY default.conf /etc/nginx/conf.d/
build & run
docker build -t foo/nginx .
docker run -p 8000:80 --link node-app:app --name nginx-proxy foo/nginx
--link
Add link to another container
-p
PORT
--name
name
curl localhost:8000
// Welcome to Node.js!
build a Tengine Web Server env in docker
docker run -it debian bash
The -it
instructs Docker to allocate a pseudo-TTY connected to the container’s stdin; creating an interactive bash shell in the container.
curl http://tengine.taobao.org/download/tengine-2.2.0.tar.gz > /opt/tengine-2.2.0.tar.gz
// curl: command not found
apt-get update
apt-get install -y curl
cd /opt
tar xzf tengine-2.2.0.tar.gz
cd tengine-2.2.0
ls
./configure
make
make install
error:
C complier cc is not found
solution:
apt-get install -y gcc
error:
the HTTP rewrite module requires the PCRE library
solution:
apt-get install -y libpcre3-dev
error:
SSL module require the OpenSSL library
solution:
apt-get install -y libssl-dev
SUCCESS run ./configure
error:
make: command not found
solution:
apt-get install -y make
SUCCESS run make && make install
/usr/local/nginx/sbin/nginx
ps aux
apt-get update
apt-get install -y curl
curl htpp://tengine.taobao.org/download/tengine-2.2.0.tar.gz > /opt/tengine.2.2.0.tar.gz
cd /opt
tar xzf tengine-2.2.0.tar.gz
cd tengine-2.2.0
apt-get install -y gcc
apt-get install -y libpcre3-dev
apt-get install -y libssl-dev
apt-get install -y make
./configure
make
make install
/usr/local/nginx/sbin/nginx
FROM debian
RUN apt-get update && apt-get install -y \
curl \
gcc \
libpcre3-dev \
libssl-dev \
make
RUN curl htpp://tengine.taobao.org/download/tengine-2.2.0.tar.gz > /opt/tengine.2.2.0.tar.gz
WORKDIR /opt
RUN tar xvf tengine-2.2.0.tar.gz
WORKDIR /opt/tengine-2.2.0
RUN ./configure
RUN make
RUN make install
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log \
&& ln -sf /dev/stderr /usr/local/nginx/logs/error.log
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
docker build -t yourname/tengine:2.2.0 .
docker images
docker run -p 8000:80 yourname/tengine:2.2.0
visit localhost:8000 // welcome to tengine!