Author
Updated
2/16/2021Released
10/3/2017Skill Level Intermediate
Duration
Views
- [Instructor] Containers offer a way of running an operating system in a controlled, confined space with much less overhead than a traditional virtual machine would require. There are a handful of technologies we can use to run containers on Linux, including Lexi and Docker. I'd like to spend a few minutes for this episode covering the basics of Docker on Linux. The container starts out with an image file representing the operating system that will run inside the container. This image contains most of an operating system. Most notably, the operating system in the image doesn't include a kernel. Containers use the host system's kernel and that means that containers on Linux can only be Linux containers, though we can run different distributions inside of containers. And for this reason, many popular containers are based on Alpine Linux, a very minimal distro that's well-suited to providing just the essentials and otherwise getting out of the way. To customize a container and control what state it has when it starts, we can write a Docker file containing commands telling Docker to do various configuration, and telling the operating system inside the container to perform certain tasks, like installing software, downloading files, or setting up some kind of configuration within the system. In many cases, we'll use standard predefined images paired with a Docker file to make customizations at launch, though we can create custom images with configurations, tools, and settings baked in. Both approaches are common and which one you use will be determined by how you need your deployment to operate. Unlike a traditional virtual machine, every time a Docker container starts up its state is returned to exactly what's contained in the image it starts from. Any changes made within the container while it runs are lost when the container stops running, unless those changes are committed to an image file. Docker containers can also be configured to start up with storage attached, giving us a way to allow the container to read and write information that will persist, and which can even be accessed by other containers at the same time. Containers allow us to modularize the services and applications, rather than running them on a monolithic server or VM. An application could be broken up into a variety of containers. For example, into an app server, a database server, and a container that handles storage. And each of these, if the application is designed correctly, can be scaled out in response to demand or easily moved to other hardware to reduce downtime if the host hardware needs to be maintained. Containers can provide some security benefits, but they're primarily a technology that gives us reproducibility, flexibility, and scalability. While it's common to use Docker directly, either for development or in production, it's also often used with an orchestration system, like Kubernetes, on top of it to manage containers and configurations. With that in mind, let's take a brief look at running a Docker container on Linux. Here on my Ubuntu system, I'll update my package lists and then I'll install Docker with apt install docker.io. On other distros the package may have a different name. For example, on Fedora or CentOS, you'd need to run dnf install docker instead. Once that's installed, I'll start the Docker service with systemctl start docker. To start up a Docker container, we'll need an image. And I can search for interesting ones with docker search and a search term. Some Docker containers are just a bare operating system and others are pre-configured with certain software, which lets us avoid having to do so much manual configuration in a Docker file. So for example, I can look for an image that's just Alpine Linux. And here I can see an official image that offers Alpine Linux. I could also search for one that includes Maria DB if I wanted to work with the database server. And here's a container that offers that. I've zoomed out a little here so we can see the formatting better. Here, I can see that this image is official. It's published by Docker themselves. To keep things simple here, I'll just get the Alpine image with docker pull alpine, and then I can use docker run to start a container using that image, and nothing happens. That's because the container only exists for as long as something's running inside it. Normally that would be a service or process or some software that waits for input to do something. We can also run specific programs inside of a container through the command line, which can be useful for development and troubleshooting. This, for example, will start the Alpine container and run the Almquist shell, the default shell in Alpine Linux, so we can look around inside the container. And here I am at the Ash prompt, and you can see that this Alpine container is running the Ubuntu kernel, even though it's Alpine Linux. I'll type Exit here and end the shell session, and then Docker will end this container. That's where I'll leave it for now. I encourage you to explore our other courses on Docker if you're interested to learn about deployment, configuration, or developing software with containerization in mind.
Related Courses
-
Linux: Bash Shell and Scripts
with Kevin Dankwardt2h 46m Intermediate -
Linux: Files and Permissions
with Grant McWilliams1h 49m Intermediate -
Linux: Multitasking at the Command Line
with Scott Simpson39m 1s Intermediate
-
New this Week:
-
Docker on Linux5m 24s
-
-
Introduction
-
Welcome1m 4s
-
-
Foundations
-
Foundations: What's Linux?5m 26s
-
Foundations: Distros10m 50s
-
Foundations: USB installer7m 46s
-
Linux on Azure7m 21s
-
Google Cloud Platform3m 37s
-
Linux on DigitalOcean6m 39s
-
-
System Basics
-
Bash operators6m 55s
-
Logs5m 4s
-
Grub3m 19s
-
SysV init4m 43s
-
Systemd5m 29s
-
Cron8m 7s
-
Understanding chroot3m 16s
-
Backing up data with rsync5m 35s
-
Working with dotfiles1m 43s
-
Exploring the PATH variable3m 51s
-
Finding or locating files3m 52s
-
Working with swap4m 29s
-
Read and write caches3m 5s
-
Filesystem Basics
-
Files on Linux4m 10s
-
File system basics: Archives6m 22s
-
Loop devices4m 35s
-
Overlay file systems4m 17s
-
Bind mounts2m
-
-
Working with Text
-
Working with text: Vim 1015m 15s
-
Working with text: Emacs 1015m 42s
-
Working with text: nano 1015m 29s
-
Working with text: grep4m 23s
-
Working with text: sed7m 24s
-
Working with text: AWK2m 51s
-
Working with text: ed 1016m 17s
-
-
Package Management
-
Package management: Basics6m 59s
-
aptitude5m 43s
-
dpkg2m 20s
-
yum and DNF4m 58s
-
RPM3m 24s
-
Creating your own packages3m 12s
-
Zypper4m 17s
-
Using Flatpak4m 11s
-
Using snaps3m 15s
-
-
Working Remotely
-
Remote files: curl and wget4m 42s
-
SSH: Secure access8m 8s
-
SSH: Tunnels3m 46s
-
X11 forwarding2m 52s
-
Using a SOCKS proxy4m 53s
-
Using a Squid proxy8m 43s
-
-
Process Management
-
Process management: ps4m 30s
-
Process management: top4m 53s
-
Process management: htop6m 11s
-
Customizing tmux3m 32s
-
-
Security
-
Firewall basics4m 5s
-
Understanding iptables6m 41s
-
File checksums3m 48s
-
Encrypting files7m 14s
-
Encrypted filesystems6m 58s
-
AppArmor4m 2s
-
Security systems: SELinux4m 33s
-
-
System Administration
-
Disks and partitions6m 42s
-
Logical volume management9m 59s
-
Create a RAID array9m 10s
-
Repairing a RAID array4m 44s
-
Local IP address5m 15s
-
DNS5m 40s
-
VPN1m 43s
-
Drivers and modules4m 16s
-
Understanding QEMU and KVM2m 49s
-
Private networking6m 37s
-
Routing and forwarding4m 26s
-
DHCP4m 55s
-
Network troubleshooting7m 42s
-
Wi-Fi on Linux4m 14s
-
-
Desktops and Displays
-
Desktops: Basics3m 8s
-
Desktops: GNOME4m 41s
-
Desktops: Xfce4m 5s
-
Desktops: KDE Plasma Desktop2m 28s
-
Desktops: LXQt3m 42s
-
-
Exploration Topics
-
Windows Subsystem for Linux7m 20s
-
Exploring virtualization5m 28s
-
Exploring containers5m 19s
-
Exploring Fedora3m 8s
-
Changing the default shell3m 30s
-
Exploring other shells2m 5s
-
Exploring CentOS2m 6s
-
Exploring Zsh5m 41s
-
Osquery4m 28s
-
Exploring fish5m 21s
-
Exploring csh and tcsh2m 34s
-
Using diff to compare files3m 54s
-
Using xargs3m 41s
-
Job control3m 59s
-
Using watch and time3m 5s
-
Recording a terminal session3m 14s
-
Exploring Debian1m 49s
-
Exploring SUSE Linux7m 33s
-
Exploring Arch Linux16m 44s
-
Exploring Alpine Linux6m 18s
-
Exploring Linux Mint5m 14s
-
Exploring Amazon Linux5m 8s
-
Terminal on the go5m 1s
-
FUSE and SSHFS3m 54s
-
Removing Linux4m 44s
-
WSL distros on Windows 103m 13s
-
Embedded Linux4m 25s
-
Exploring Netboot2m 43s
-
Exploring ZFS3m 53s
-
Troubleshooting Topics
-
Projects
-
Linux on an old PC6m 7s
-
Hosting email services3m 7s
-
Create a network PDF printer4m 37s
-
Remote logging with Rsyslog7m 12s
-
Set up a Git server4m 16s
-
NGINX web server4m 11s
-
Set up an NFS server3m 58s
-
Monitoring your server2m 49s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Docker on Linux