Friday, March 23, 2018

Docker



Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. 


Today’s businesses are under pressure to digitally transform but are constrained by existing applications and infrastructure while rationalizing an increasingly diverse portfolio of clouds, datacenters and application architectures.



 Docker enables true independence between applications and infrastructure and developers and IT ops to unlock their potential and creates a model for better collaboration and innovation.






















docker container run httpd:2.4



But there's a little problem: We should be able to access the defaultindex.html page on that server by visitinghttp://localhost:80/index.html

but when we do that we just get an error that we can't connect to port 80. 

Fortunately, we can solve this by adding a -p flag with some port numbers after it to the runcommand.


docker container run -p 80:80 httpd:2.4



Port 80 is a standard port for handling web requests, but we could map any port on the host to the container. Let's try mapping 9999 on the host to 80 on the container.



docker container run -p 9999:80 httpd:2.4



docker container execcommand lets us run commands against a running container. But before we can run a command, we need to know the ID of the container.


docker container ls

W
$ docker container ls
CONTAINER ID        IMAGE               COMMAND              CREATED
 STATUS                 PORTS                  NAMES
a8c267869b0b        httpd:2.4           "httpd-foreground"   53 seconds ago

Up 52 seconds       0.0.0.0:9999->80/tcp   elegant_noether




Each container gets a unique ID, and Docker also assigns them a random name. You can use either the container ID or the container name whenever you're running a command that needs you to specify a container. In this course, every container you create has the name elegant_noether, so try executing the command below on that container.
Type docker container exec elegant_noether du -mh.




Attaching a Shell to a Container 250 PTS


Running commands is cool, but we can also attach a shell to those containers and browse them just like they were a full operating system — which they kind of are. The -i and -t flags can be passed to theexec command to keep an interactive shell open, and you can specify the shell you want to attach after the container ID. Here we'll attach a standard Bash shell.
docker container exec -it elegant_noether /bin/bash.


We're in! From the perspective of the terminal window we're just navigating a normal Unix system, so any commands we type will run inside of that system. Try typing that same command we just ran with exec from inside the container.
Type du -mh




Installing packages

docker container exec -it elegant_noether /bin/bash

apt-get install -y fortunes

/usr/games/fortune
  1. Placeholder Badge

    Level 2

    Dockerfiles

  2. Placeholder Badge

    Level 3

    Volumes

































No comments:

Post a Comment