The intro to Docker I wish I had when I started

typecraft
15 Jul 202418:26

Summary

TLDRThis video introduces Docker, explaining the fundamental differences between virtualization and containerization. The speaker discusses how Docker helps manage lightweight, isolated environments called containers, which are commonly used in web development, continuous integration, and cloud deployment. Key concepts such as Docker files, images, and containers are explained, showing how they work together to streamline development and deployment. The video provides a step-by-step guide on setting up and using Docker, emphasizing its importance in modern web development and encouraging further learning on advanced topics.

Takeaways

  • πŸ“¦ Docker is a tool that helps manage the life cycle of containers, used in various web development processes like continuous integration and deployment.
  • πŸ” Containers are lightweight, isolated environments where processes run, and are used in many common web development workflows, even if developers aren't aware of it.
  • πŸ’» Virtualization involves creating entire virtual machines with dedicated hardware resources, whereas containerization shares the host's OS but isolates processes.
  • πŸ–₯️ Docker makes containerization easier by automating the management of containers, so developers don't need to handle process isolation manually.
  • 🌐 Docker images are templates used to create containers, and Docker Hub is a repository where developers can pull pre-made images like 'hello-world' or 'Postgres'.
  • πŸ“„ A Dockerfile contains instructions to build a Docker image, such as specifying a base image and commands to run inside the image (e.g., installing software).
  • πŸ”§ Docker containers are created from images and run isolated processes, making them ideal for replicating environments across different machines.
  • πŸ”„ Docker images are immutable; once built, they don’t change. If modifications are needed, a new image version is created using a modified Dockerfile.
  • πŸ“‚ Docker Compose, volume mounting, and port mapping are additional features that can enhance the use of Docker in complex projects.
  • πŸš€ Using Docker in development allows for consistent, reproducible environments, reducing issues with dependencies across different setups.

Q & A

  • What is Docker and why is it important for developers to learn?

    -Docker is a tool that manages the lifecycle of containers, allowing developers to create reproducible, lightweight environments for running processes. It's important because containers are used in many aspects of modern development, including continuous integration, continuous deployment, and cloud deployments.

  • What is the main difference between virtualization and containerization?

    -Virtualization involves creating virtual machines (VMs) with their own operating system, while containerization uses the host machine's operating system but isolates processes in containers. VMs require a hypervisor to manage them, whereas containers are more lightweight and efficient.

  • What role does a hypervisor play in virtualization?

    -A hypervisor manages the lifecycle of virtual machines. It provisions resources, starts, stops, and deletes virtual machines. Common hypervisors include VMware and VirtualBox.

  • What is a Docker container?

    -A Docker container is a lightweight, isolated environment that shares the host's operating system but runs processes independently. Containers cannot access resources outside their environment unless explicitly allowed.

  • How does Docker manage container lifecycles?

    -Docker uses commands to build, run, and manage containers. It simplifies the manual process of setting up containers and managing their resources, allowing developers to easily create isolated environments.

  • What is a Docker image, and how is it related to containers?

    -A Docker image is a snapshot of a file system that includes everything needed to run a container, such as code, dependencies, and libraries. Containers are instances of these images, running the processes defined in the Docker image.

  • What is the purpose of a Dockerfile?

    -A Dockerfile is a set of instructions that tells Docker how to build an image. It specifies the base image, what dependencies to install, what files to copy, and what commands to run inside the image.

  • What does the 'docker build' command do?

    -The 'docker build' command reads the instructions from a Dockerfile and creates a Docker image. You can also specify a tag (name) for the image, allowing you to keep track of different versions.

  • What happens when you run the 'docker run' command?

    -The 'docker run' command creates a container from a Docker image and executes the default command specified in the Dockerfile. It runs the container in isolation, based on the image's environment and code.

  • Can Docker images be modified after they are built?

    -No, Docker images are immutable, meaning they cannot be changed after being built. If you want to make changes, you need to modify the Dockerfile and build a new image with a different tag.

Outlines

00:00

🐳 Introduction to Docker and Containerization

The speaker begins by sharing their personal journey with Docker, acknowledging that despite being a Ruby on Rails developer, they didn't need to use Docker extensively. They recount their initial resistance to Docker, humorously stating their lack of knowledge about it. However, they realize that Docker is a fundamental technology that they should have understood earlier. The paragraph sets the stage for an educational video that will explain virtualization and containerization, clarify the differences between them, and introduce Docker files, images, and containers. The speaker emphasizes the importance of Docker in web development, noting its prevalence in continuous integration/continuous deployment (CI/CD) pipelines and cloud deployments. The paragraph concludes with a teaser about getting hands-on with Docker in the video.

05:02

πŸ”§ Understanding Virtualization and Docker Installation

This paragraph delves into the concept of virtualization, explaining it as the process of creating a virtual machine (VM) on a host machine, complete with its own operating system. The speaker mentions that VMs are commonly used in cloud services like AWS EC2 instances. They introduce the term 'hypervisor,' which is a program that manages VMs, with examples like VMware and VirtualBox. The paragraph then transitions into containerization, contrasting it with virtualization. Containerization is described as a method to run processes in isolated environments on a host PC without the overhead of a full VM. The speaker clarifies that while both technologies are similar, they serve different purposes. Docker is then introduced as a tool that manages container lifecycles. The paragraph concludes with a practical demonstration of installing Docker on the speaker's Arch Linux system using the Pac-Man package manager.

10:03

πŸ“ Docker File and Image Creation

The speaker explains the process of Docker image creation using a Dockerfile. They provide an example of a Dockerfile that uses the 'FROM' instruction to base the image on the latest Ubuntu image. The Dockerfile is used to update the package index, install packages, copy local directories into the image, and define default commands for the container. The paragraph walks through the Dockerfile step by step, illustrating how each line contributes to building the image. The speaker emphasizes that Docker images are immutable, meaning that any changes require the creation of a new image. They also discuss the process of running a container from an image using the 'docker run' command and how the container's default command is specified in the Dockerfile.

15:05

πŸš€ Practical Docker Usage and Image Versioning

In this paragraph, the speaker demonstrates a practical example of using Docker by creating a container that runs a script to display ASCII art. They walk through the contents of a Dockerfile and a script file, explaining how the Dockerfile installs necessary packages, copies the script into the image, and sets the default command to run the script. The speaker then shows how to build the Docker image using the 'docker build' command and run a container from the image using 'docker run'. They also discuss the immutability of Docker images and how to create a new image with changes by editing the Dockerfile and building a new version with a different tag. The paragraph concludes with the speaker running both the original and the updated containers to show how Docker handles multiple versions of the same image.

Mindmap

Keywords

πŸ’‘Docker

Docker is a platform that automates the creation, deployment, and management of containers. In the video, Docker is introduced as a tool for managing containerization, allowing developers to run isolated environments. The speaker emphasizes Docker's significance in web development and continuous deployment, highlighting its utility for running lightweight, reproducible environments.

πŸ’‘Container

A container is a lightweight, isolated environment for running processes. Containers allow developers to package applications and dependencies together, ensuring consistency across various environments. In the video, the speaker describes containers as 'bounded boxes' where processes can run without affecting the host system, and they are integral to Docker's functionality.

πŸ’‘Virtualization

Virtualization is the process of creating a virtual version of a machine, including its operating system and resources. The video contrasts virtualization with containerization, explaining how virtualization involves running full operating systems on virtual machines, often managed by a hypervisor, whereas containerization is a more lightweight alternative.

πŸ’‘Hypervisor

A hypervisor is software that manages virtual machines (VMs), handling their creation, allocation of resources, and lifecycle. In the context of the video, hypervisors like VMware and VirtualBox are mentioned as tools used in virtualization, making them distinct from Docker, which is designed to manage containers rather than full VMs.

πŸ’‘Docker File

A Docker file is a script containing instructions for building a Docker image. The video provides an example of a Docker file that specifies how to build an image by including commands such as installing software or copying files. The speaker emphasizes the role of Docker files in defining the environment and behavior of Docker containers.

πŸ’‘Image

In Docker, an image is a read-only template that contains the application code and dependencies needed to run a container. The video describes how Docker images are built using Docker files and how they are immutable once created. The speaker uses the example of building an image from a coffee recipe application and running it as a container.

πŸ’‘Docker Hub

Docker Hub is a repository where Docker images are stored and shared. The video references Docker Hub when discussing how Docker pulls images like 'hello-world' from this repository. Docker Hub allows developers to easily find pre-built images for common applications like PostgreSQL, saving time by not requiring them to build images from scratch.

πŸ’‘Continuous Integration (CI)

Continuous Integration (CI) is a development practice where code changes are automatically tested and integrated into the project. The video mentions CI pipelines in the context of container usage, explaining how containers are often part of the CI process, providing isolated environments to test and deploy applications consistently.

πŸ’‘Continuous Deployment (CD)

Continuous Deployment (CD) is an extension of Continuous Integration where code changes that pass automated tests are automatically deployed to production. The video highlights how containerization through Docker is essential in CD pipelines, as containers provide consistent environments that make deployments smoother and more reliable.

πŸ’‘Immutable

In the context of Docker, 'immutable' refers to the fact that Docker images cannot be changed after they are built. The video stresses this immutability by explaining that if changes are needed, a new version of the image must be created. This ensures that containers based on an image will always have the same environment, making deployments more predictable.

Highlights

Docker was often underutilized in my career as a Ruby on Rails developer, with the common joke 'Docker? Barely even know her!'

Containers are pivotal for web developers because they create reproducible, lightweight environments, commonly used in CI/CD pipelines and cloud deployments.

Virtualization involves running full operating systems on virtual machines with hardware resource allocation managed by a hypervisor.

In contrast, containerization isolates processes within a host machine using tools like `chroot` and `rlimit` for resource limits and environment boundaries.

Docker simplifies containerization by managing container life cycles, from creation to execution, through its CLI and infrastructure.

A Docker image is a blueprint for containers, often pulled from Docker Hub, which serves as a repository for pre-built images.

A Docker container is the running instance of an image, isolated from the rest of the system, executing specified processes.

Dockerfiles are scripts that define the steps to build an image, including instructions like copying files and setting up the environment.

Images are immutable snapshots of the file system and environment, and containers run them based on commands specified in the Dockerfile.

Docker Hub is a vast repository where developers can search for pre-built images, such as Postgres, reducing the need to build from scratch.

In a basic example, running `docker run hello-world` pulls the image from Docker Hub and verifies the installation by running a test container.

Using `docker build`, developers can create images from Dockerfiles and tag them to create different versions without overwriting the previous image.

By building and running a container that prints random ASCII messages using a bash script, the process showcases Docker’s ability to automate tasks within isolated environments.

Each change to the code or environment requires building a new Docker image, demonstrating the immutability of images in Docker.

Multiple images with different tags can coexist, allowing developers to run different container versions, preserving previous states for testing or deployment.

Docker serves as an essential tool for modern development, enabling isolated, reproducible environments critical for CI/CD, deployment, and scalable applications.

Transcripts

play00:00

for the longest time Docker was a tool

play00:01

that I used sparingly throughout my

play00:03

whole career I mean I'm a Ruby on Rails

play00:05

Dev I don't have to know Docker I can

play00:07

just run all my services locally on my

play00:09

machine right I can even remember

play00:10

throughout my career if anyone ever

play00:12

mentioned that we needed to use Docker

play00:13

to run something I would always say

play00:15

Docker barely even know her and as

play00:16

hilarious as that joke is I was missing

play00:19

out on a core foundational piece of

play00:21

technology that I should have known

play00:22

about all along in this video we're

play00:24

going to cover virtualization and

play00:26

containerization and what the difference

play00:27

is between the two things because for me

play00:29

this was always messed up in my head

play00:31

we're also going to cover Docker files

play00:33

images Docker containers and how they

play00:35

all fit into the grand scheme of Docker

play00:37

this video is going to be a gentle

play00:38

introduction to Docker and we're just

play00:40

going to be scratching the surface so

play00:41

stick around this is going to be a fun

play00:50

[Music]

play00:53

one so why is Docker an important thing

play00:56

to learn in the first place well you see

play00:58

you probably use containers and

play01:00

containerization Technologies every

play01:02

single day of your career if you're a

play01:03

web developer even if you don't realize

play01:05

it containers are a way to build

play01:07

reproducible lightweight environments

play01:09

for processes to run and we use them

play01:11

everywhere in continuous integration and

play01:13

continuous deployment pipelines like on

play01:15

GitHub actions that you probably use all

play01:17

the time and we also use it whenever

play01:19

you're deploying to a server if you

play01:20

deploy something to the cloud chances

play01:22

are you're interacting with container

play01:24

technology somewhere along the way so I

play01:26

think it's a pivotal thing that you need

play01:27

to learn in your web development career

play01:30

but wait what the hell is a container

play01:31

anyways in order to talk about

play01:33

containers we should talk about

play01:34

virtualization now bear with me for a

play01:36

minute because these two things are very

play01:38

closely related and I think it's

play01:39

important to understand the distinctions

play01:41

between the two technologies so let's

play01:43

talk about virtualization so let's draw

play01:44

up how virtualization Works in a typical

play01:46

sense and we can talk through it now

play01:48

typically when it comes to

play01:51

virtualization you start off with a host

play01:53

machine this could be your host now the

play01:56

host could be anything it could be your

play01:57

local PC it could be a server up in the

play01:59

cloud server in a data center somewhere

play02:01

whatever it is it's a piece of Hardware

play02:03

now in this piece of Hardware you have

play02:05

different things that control how this

play02:06

Hardware works you have things like your

play02:09

CPU you also have things like memory and

play02:13

you have your hard drive we'll call this

play02:14

IO now when it comes of virtualization

play02:17

what happens is we take little pieces of

play02:19

each of these pieces of hardware and

play02:21

separate them out into a separate

play02:23

machine this is a virtual machine and

play02:26

then we take these pieces of hardware

play02:27

and in this virtual machine we actually

play02:30

run a full entire operating system now

play02:33

this technique is commonly used in the

play02:34

cloud if you're deploying something to

play02:36

AWS or an ec2 instance typically what

play02:38

you're doing is you're spinning up a new

play02:40

virtual machine that you can then deploy

play02:42

your code onto now virtual machines have

play02:44

a special type of program that can run

play02:47

and manage the life cycle of these

play02:48

machines this program is called a

play02:50

hypervisor and the hypervisor is in

play02:52

charge of virtual machines it manages

play02:54

the life cycle it starts them up it

play02:56

stops them it creates them it deletes

play02:58

them it Provisions resources for for

play03:00

them that is what the hypervisor does

play03:01

now a common hypervisor that you would

play03:03

be aware of is VMware or virtual box

play03:06

these are the programs that control the

play03:08

virtual machines now virtualization is

play03:10

similar but it differs from

play03:12

containerization which is the thing that

play03:14

Docker is kind of based around so let's

play03:16

talk about containerization in a

play03:17

container setup what you would do is you

play03:19

would have a host PC much like the

play03:21

virtualization setup that we set up

play03:23

before now let's say on this host PC we

play03:25

want to run a set of processes but we

play03:27

want these processes to run in isolation

play03:29

we don't want them to touch anything

play03:31

else now we can achieve that using some

play03:33

techniques right let's say we want these

play03:35

processes to run on this machine

play03:37

processes what we do is we can use some

play03:39

techniques like the CH root command

play03:41

which will create a new route for a

play03:43

process so it can only live inside that

play03:45

root and it can't touch anything outside

play03:47

of that like any of the other users

play03:49

directories or things like that that are

play03:50

already on the system we could also use

play03:52

a kernel feature like the r limit

play03:54

feature which will limit the amount of

play03:55

resources these processes take up these

play03:58

techniques amongst other things will en

play03:59

Compass what is containerization now

play04:02

with containerization you could do all

play04:04

this manually yourself but it's really

play04:06

difficult and pretty tricky so there are

play04:08

programs that help manage the life cycle

play04:10

of your containers this is where Docker

play04:13

comes into play Docker is a program that

play04:15

manages the life cycles of containers

play04:18

edit them run them and interact with

play04:20

them so to sum up containerization is

play04:22

the ability to create a lightweight

play04:24

environment where processes can run on a

play04:26

host operating system they share all the

play04:28

same things in that operating system

play04:29

system but they cannot touch anything

play04:31

outside of their little bounded box Okay

play04:33

so we've talked enough about

play04:35

virtualization and containerization

play04:37

let's see containerization through

play04:38

Docker in work let's get our hands dirty

play04:41

so now let's install Docker again this

play04:43

is this portion of our graph right here

play04:45

this is the management layer that will

play04:47

manage the life cycles of all of our

play04:49

containers that we want to create that's

play04:51

what Docker does for us now to install

play04:53

Docker there are examples of how to

play04:55

install it on the docker website for me

play04:57

I use Arch Linux by the way so I going

play04:59

to use Pac-Man to install Docker and

play05:02

it's as simple as that Docker is now

play05:05

installed so how do we know that Docker

play05:06

is even running correctly on our system

play05:08

well Docker gives us a helpful command

play05:10

that we can run to sort of give us our

play05:12

first taste of what Docker will do for

play05:14

us we can do Docker space run space

play05:17

hello hyphen world let's see what

play05:20

happens we're going to break down this

play05:21

command in a little bit but let's just

play05:22

see what happens

play05:24

now okay a lot of stuff just happened

play05:26

let's go through this line by line and

play05:28

let's see what Docker is telling telling

play05:29

us that it did now to start off with

play05:31

Docker was unable to find the image

play05:33

hello world latest now this is the name

play05:36

of our image and this is the tag of our

play05:38

image now in Docker speak an image is

play05:40

basically the thing we run our

play05:42

containers from I'll explain it again in

play05:43

a second and latest is the tag of that

play05:46

image by default doer tags its images

play05:48

with the latest tag so doer was unable

play05:51

to find the image hello world latest

play05:53

locally so it pulls it from a repository

play05:56

Docker will pull images that are already

play05:58

known from dockerhub we can actually

play06:01

check out dockerhub by going to hub.

play06:03

do.com and this is where you can see all

play06:06

of the images that Docker already has

play06:09

pre-built in this platform here Docker

play06:11

hubs this is where you can explore if I

play06:13

wanted to look for like let's say a

play06:14

postgress image here it is right here I

play06:16

can use the postgress image from Docker

play06:18

Hub I don't have to build one myself so

play06:20

Docker Hub is very helpful and that's

play06:22

what it does here it pulls the hello

play06:24

world image from Docker Hub and as you

play06:26

can see here it says status downloaded

play06:28

newer image for hello World latest

play06:30

awesome and then it says hello from

play06:32

Docker this is the actual image running

play06:35

a container I'll explain this in one

play06:36

second here this message shows that your

play06:38

installation appears to be working

play06:39

correctly to generate this message

play06:41

Docker took the following steps the

play06:43

client contacted the docker Damon the

play06:44

docker Damon pulled the hello world

play06:46

image from Docker Hub that's what we

play06:48

were just talking about and then the

play06:49

Damon created a new container for us

play06:51

from the image okay and now the docker

play06:54

Damon streamed that output to the docker

play06:56

client which sent it to your terminal

play06:58

okay let's unpack this a little bit you

play07:00

might be asking yourself what the hell

play07:02

is an image and how does Docker know how

play07:04

to build these things and run containers

play07:07

from images what is all this stuff now

play07:09

before we talk about how to build images

play07:11

and how to then run containers from the

play07:12

images we have to talk about something

play07:14

called a Docker file this is an example

play07:16

doer file and it's pretty contrived but

play07:19

essentially what you would have with any

play07:21

project anything you want to build an

play07:22

image out of is you would have a

play07:24

directory structure that looks something

play07:25

like this in this contrived example we

play07:27

have a directory that can contains a

play07:30

Docker file and within the docker file

play07:32

we have a coffee recipe folder let's

play07:34

just imagine that this is a coffee

play07:36

recipe application of some sort in this

play07:38

coffee recipe folder we have two scripts

play07:40

prepare Beans and Brew Coffee okay so

play07:43

now let's talk about what this Docker

play07:45

file is doing you can see on this very

play07:47

first line we have from Ubuntu latest

play07:49

now you might remember this terminology

play07:51

from not too long ago that means that we

play07:53

want to use the Ubuntu image at the

play07:57

latest tag this is the terminology for

play08:01

an image and the tag for that image

play08:03

Ubuntu latest okay great the next line

play08:06

says we want to run appt get update and

play08:09

appt get install some contrived package

play08:11

what is this this line tells Docker that

play08:15

we want to run something on the image

play08:18

that was added above so we're running

play08:21

apt get update and apt get install on

play08:23

our auntu latest image so this runs

play08:27

command on the image next what we want

play08:30

to do is copy the coffee recipe

play08:33

directory from our local file system

play08:36

into this image so what we want to do

play08:38

here is basically just copy things from

play08:40

our local directory again you can

play08:42

remember our directory structure looks

play08:44

like this we have the coffee recipe

play08:46

directory and under this we have a

play08:48

couple of scripts so we want to copy the

play08:49

coffee recipe directory into this image

play08:52

next we want to run in our image the

play08:54

script prepare beans. sh so this will

play08:57

run that script now remember since we

play08:59

copied the directory into our image we

play09:02

will have this available to us because

play09:04

prepared beans is right here oh look I

play09:06

misspelled it how fun and then next we

play09:09

have this line that says command Now

play09:11

command is the default command that this

play09:13

container is going to run it's this can

play09:15

be overwritten in the CLI but by default

play09:17

we're going to run the Brew Coffee

play09:19

command this is the default command for

play09:22

our Docker image so when the darker

play09:24

container runs it's going to run this

play09:26

default command so now let's zoom out a

play09:28

little bit here what we are going to do

play09:30

is we are going to take in this

play09:32

contrived example this Docker file and

play09:35

from this Docker file we are going to

play09:37

build a Docker image now this image we

play09:40

could name anything but let's just call

play09:42

it coffee right this image by default

play09:44

will create will be called coffee at the

play09:47

latest tag you can give an image

play09:49

whatever tag you want but again by

play09:51

default Docker gives a tag of latest to

play09:53

every image now this image is almost

play09:56

like the file system for the container

play09:58

to run and it's immutable you can only

play10:01

build one image you don't change your

play10:03

images what you do if you want to change

play10:05

anything is you change your Docker file

play10:07

and then build a new version of your

play10:09

image for containers to run now from our

play10:12

image what we want to do is we want to

play10:14

call Docker run and that will then run

play10:17

our container and our container as we

play10:19

said before will call the Run command

play10:22

that we specified in our darker file

play10:24

which was Brew coffee.

play10:27

sh and again to actually build the image

play10:30

we want to run Docker build and there

play10:32

are certain Flags we can pass to build

play10:34

like I said to change the tag of the

play10:36

image from the default of latest you can

play10:38

also name the image whatever you want

play10:40

but this is generally the process for

play10:42

Docker we want to create a Docker file

play10:44

in some repository or in our directory

play10:46

we want to then use this Docker file as

play10:48

the instructions to build a new image

play10:51

for Docker then we can run this image

play10:53

and Docker will spin up a new container

play10:55

on our system that is not able to touch

play10:58

anything else within our system and it

play11:00

will run whatever code we want it to run

play11:02

using the command flag so that in a

play11:04

nutshell is how Docker sets up Docker

play11:07

files images and containers okay so now

play11:09

we have all of our Core Concepts in

play11:11

place we understand the relationship

play11:12

between a Docker file how a Docker file

play11:14

is the instructions to build a Docker

play11:16

image and then how a Docker image is

play11:18

used to then run a Docker container all

play11:21

underneath the umbrella of the docker

play11:23

CLI so let's get our hands dirty and

play11:25

actually try out a real world example

play11:27

this is going to be a simple example

play11:29

it's a contrived example yet again but

play11:31

we're actually going to run a real

play11:33

container on our system to get a feel

play11:35

for how the docker CLI works now let's

play11:37

just say I have a directory called

play11:39

Docker example and in this directory I

play11:40

have two files a Docker file and a print

play11:43

message. sh file let's take a look at

play11:45

them let's start first with our print

play11:47

message. sh we can see that it is a bash

play11:50

script and then it has a variable that

play11:52

has a list of phrases these phrases are

play11:55

then randomly selected and we print them

play11:57

out to the terminal using a a program

play12:00

called figlet now what if I don't have

play12:02

figlet installed on my local machine

play12:04

well that's okay that's why we have this

play12:05

Docker file so in our Docker file what

play12:07

we want to do as we've seen before we

play12:09

want to use auntu latest that means

play12:11

we're using the latest version of the

play12:12

auntu image from Docker probably from

play12:14

Docker Hub then on that image we want to

play12:17

run apt get update and apt get install

play12:19

figlet and wget we're going to use WG

play12:22

get in the next line where we run W get

play12:25

and we W get some fonts that we want to

play12:28

then install on our system then we want

play12:30

to copy our local print message script

play12:33

into the Container for print m.sh this

play12:36

is what we're actually going to run then

play12:38

we want to chamod plus X print m.sh that

play12:42

just makes this script executable inside

play12:44

of the container and our final command

play12:46

is to just run print message. SSH it's a

play12:48

pretty simple Docker file but this will

play12:50

give us an understanding of how to use

play12:52

these things in real time so now that

play12:54

we're within this directory that has a

play12:55

doer file we can call from within the

play12:58

directory Docker build now in Docker

play13:01

build we could tag that by default it

play13:03

will tag it with the latest release and

play13:04

we can call this asky and we want to

play13:07

make sure we build everything in this

play13:08

current directory this will build our

play13:10

very first image let's see what this

play13:12

command does okay this was a lot of

play13:14

stuff but let's just go through it

play13:15

really quickly and see what we did here

play13:17

we can see that it sent the build

play13:19

context to the docker Damon and then we

play13:21

did the steps that were in the docker

play13:22

file we can see the docker file working

play13:24

for us step one out of six from auntu

play13:27

latest now it pulls from Library auntu

play13:30

this is probably pulling from dockerhub

play13:31

we then run appt get update and app get

play13:34

install these couple of programs onto

play13:36

our abtu image very good we can see that

play13:38

that is running and that's what all this

play13:40

output is and then in our next step step

play13:42

three we want to run W get for these

play13:44

files now these files were then taken

play13:47

and saved into this image very good and

play13:50

now in step four out of six we copy our

play13:52

local print message script into the

play13:53

image then we run chamod plus X which

play13:56

will make it executable and at the very

play13:58

end we want to make sure our default

play13:59

command is just by running this print

play14:02

message script cool okay so now we have

play14:04

our image built how do we run the

play14:06

container based on this image well what

play14:08

we can do is we can check what images we

play14:10

have currently built on our system with

play14:12

the docker images command we hit enter

play14:15

and we can see that amongst a couple

play14:16

others like Ubuntu and hello world we

play14:18

have our asky image tagged at the latest

play14:21

tag with an image ID created about a

play14:23

minute ago and that's what we have right

play14:25

here we built our image I'm going to

play14:27

make my font smaller here because we're

play14:28

printing out asky text and it's going to

play14:30

be pretty large on the screen you'll see

play14:32

what I mean in a second but basically

play14:33

what we want to do is now that we have

play14:35

our image built we can run Docker run

play14:38

and then type the name of the image

play14:40

which is asky we could also optionally

play14:42

add the tag which would be latest and

play14:44

I'll just add it right here if we do

play14:46

this and enter Then This command we can

play14:48

see that it actually runs the container

play14:50

and it runs the script that prints out

play14:52

asky art to our screen isn't that

play14:55

awesome so basically what we've done

play14:56

here is we have now a Docker file that

play14:58

installs STS things into an image we

play15:00

have an image that has all these

play15:01

programs on it like figlet w get and

play15:04

everything else and then it has a script

play15:06

inside of that image as well now the

play15:07

container runs and the container's

play15:09

default command is to then print this

play15:11

stuff out to the terminal and that's

play15:13

what it is we just did that awesome now

play15:15

we can keep running this command we can

play15:17

keep running this Docker container and

play15:19

it will just randomly select another

play15:21

thing apparently it was the same for a

play15:23

bunch of those but it will select random

play15:25

sayings and then print them out in an

play15:26

asky text to us very cool but now let's

play15:29

say we want to modify this script and we

play15:31

want to print out different things what

play15:32

do we do now to update this image well

play15:35

images are immutable what you're going

play15:37

to have to do is edit your Docker file

play15:38

and then create a new image probably

play15:40

with a different tag let's get into that

play15:43

so we see we have our Docker file here

play15:45

and we have our print message. sh let's

play15:47

just say we want to change some of these

play15:51

phrases this is

play15:53

fun I love

play15:56

Docker cool okay so now we've changed

play15:58

the script that actually prints the

play15:59

messages out what we're going to want to

play16:00

do is build a new image from this Docker

play16:03

file because this new image is going to

play16:05

contain different things okay so let's

play16:07

do Docker

play16:09

build- T and what we want to do is we

play16:12

want to name this asky with a colon the

play16:15

colon is going to denote the tag and I'm

play16:18

just going to call it different we can

play16:19

call whatever we want and we want to

play16:20

build it from our local directory now

play16:22

let's hit enter so we can see here we

play16:24

get very similar output to what we had

play16:26

before we probably get less output

play16:27

because we already have the ab image

play16:29

installed and we already have these

play16:30

programs installed in the abutu image

play16:33

that Docker is using to build this image

play16:35

but we can see down below we've

play16:36

successfully built this new image which

play16:38

has a new ID and there's a new tag

play16:40

called asky different very cool all

play16:43

right so now let's check Docker images

play16:45

to see what this looks like okay great

play16:46

we can see that we have as's latest

play16:48

build which isn't currently the latest

play16:50

because we tagged it with something

play16:51

different but that's okay for now and we

play16:53

have our new asky different tag so this

play16:56

tag is a snapshot of our Docker file

play17:00

that was built into an image so now

play17:01

let's run our new image in a container

play17:04

we can call Docker run asky and we want

play17:07

to add the tag of different let's see

play17:09

what happens you can see it pushes out

play17:11

the different text that we did now we

play17:13

have different sayings that we're

play17:14

putting out there like I love you or I

play17:16

love Docker let's make this a little bit

play17:17

smaller so we can see it a little bit

play17:18

better but I love Docker this is fun I

play17:22

love you these are all the different

play17:23

messages that we put in our print

play17:25

message Dosh now the cool thing is we

play17:27

still have the previous version of this

play17:29

image like I said they're immutable you

play17:30

don't change the images you just create

play17:32

new ones so we can also say Docker run

play17:36

asky latest and that was the previous

play17:38

one that we built which has all of these

play17:40

Star Wars things in there let's make

play17:42

this smaller so we can run both of our

play17:45

containers based on the images that

play17:47

we've built the images are mutable you

play17:49

don't delete them you just create new

play17:50

versions of them very cool so what have

play17:52

we learned here well I think we've

play17:54

learned a lot we've learned about the

play17:55

difference between virtualization and

play17:57

containerization and we've also learned

play17:59

about Docker as a whole and how Docker

play18:01

files images and containers all relate

play18:04

to one another but this is just the

play18:06

surface of this surface that we're

play18:07

scratching here if you want to learn

play18:09

more about Docker like Docker compose

play18:11

mounting Docker volumes or even doing

play18:13

things like Port mapping and darker then

play18:15

leave a comment down below of what you

play18:16

would like to learn next and hey thanks

play18:19

nerds

play18:20

[Music]

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Docker basicsContainerizationVirtualizationWeb developmentDocker tutorialBeginners guideDocker imagesDevOps toolsRuby on RailsSoftware development