Introduction to Docker
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    What is included in a container?

    A container is a portable computing environment, but what is included exactly? --> A container contains everything needed to run a workflow or application; dependencies, code, and configuration.

    The Docker client and the Docker daemon make up the two main parts of Docker its server-client architecture. The API specifications make it clear how the client and external applications can talk with the daemon.

    Containers and images

    Getting an intuitive understanding on Docker and the many new concepts surrounding it can be difficult, especially the difference between images and containers can seem blurry because they are closely related. Did you fully grasp the difference? --> Images are blueprints, while a container is a running image, the image is just the template it got started from.

    Containers are like processes

    Looking at containers as processes can help make them less abstract and create a mental model of how they work. Are you able to understand the difference between a normal process and how containers are run?

    - Can run its own Operating System.

    - Its started and kept track of by the Docker daemon.

    - Is isolated from seeing or accesing any other processes.

    - Any processes it starts will be isolated from the host OS.

    - Can only access part of the file system dedicated to process.

    What is virtualization?

    You just learned about virtual machines and containers, both of which are virtualization technologies, but do you remember what that means exactly? --> - The goal of virtualization is to run multiple pieces of software isolated from each other on the same machine.

    - Virtualization allows an operating system to run on top of another operating system.

    - Virtualization is when system resources like RAM, CPU, or Disk can be ‘virtualized’ and represented as multiple resources.

    How do containers and virtual machines relate?

    Which of the following answers best describes the relationship between containers and virtual machines?

    --> Containers and virtual machines are both virtualization technologies, but they have different strengths and weaknesses, making their use cases different.

    Containers

    • Is faster to start and iterate on then its counterpart.
    • Large ecosystem of pre-made options with many popular software applications like programming languages, databases or web-servers pre-installed.
    • Virtualization happens in a software layer above the operating system level.
    • Is much smaller in comparison both on disk and in memory.

    Virtual Machines

    • Is the best option if security is the main concern.
    • Supports applications with a graphical user interface.
    • Has virtualization down to the hardware.
    • No software is shared between different instances.

    Running your first container

    Now that you know how to start and stop containers, look at running containers, and much more, let's get your hands dirty! We'll start off by just running a container that outputs some text so we can see that it successfully ran. In other words, it's your turn to run a hello-world container!

    docker run hello-world

    Running a container in the background

    You got some projects set up already on your machine, but an urgent request has come in to fix a bug in your data ingestion pipeline. The pipeline is used to store data from different sources into a Postgres database. To search for the issue, you want to set up the project locally together with a Postgres database in a Docker container to ensure that fixing this bug doesn't affect anything else you are working on.

    1. Using the terminal, enter the command to run the postgres image in the background. --> docker run -d postgres
    2. Make sure the container is running by listing all containers and verifying that you see a Postgres container running. --> docker ps

    Stopping a container

    You were able to fix the bug in the pipeline and want to get back to other work; before you can resume your previous task, you would like to shut down the database you used to run the pipeline app locally. Which answer correctly cleans up the running Postgres container?

    docker stop container-id

    It's always good practice to stop containers once you're done using them, or one day you'll find a bunch of running containers on your machine without knowing if they are safe to shut down.