Tuesday, November 3, 2020

Quick start: Set up your Docker environment

 Docker concepts

Images and containers

Fundamentally, a container is nothing but a running process, with some added encapsulation features applied to it in order to keep it isolated from the host and from other containers. One of the most important aspects of container isolation is that each container interacts with its own private filesystem; this filesystem is provided by a Docker image. An image includes everything needed to run an application - the code or binary, runtimes, dependencies, and any other filesystem objects required.

Containers and virtual machines

A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.

By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs incur a lot of overhead beyond what is being consumed by your application logic.

Container stack exampleVirtual machine stack example

Set up your Docker environment

Download and install Docker Desktop

...

Test Docker version

After you’ve successfully installed Docker Desktop, open a terminal and run docker --version to check the version of Docker installed on your machine.

$ docker --version
Docker version 19.03.13, build 4484c46d9d

Test Docker installation

  1. Test that your installation works by running the hello-world Docker image:

        $ docker run hello-world
    
        Unable to find image 'hello-world:latest' locally
        latest: Pulling from library/hello-world
        ca4f61b1923c: Pull complete
        Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
        Status: Downloaded newer image for hello-world:latest
    
        Hello from Docker!
        This message shows that your installation appears to be working correctly.
        ...
    
  2. Run docker image ls to list the hello-world image that you downloaded to your machine.

  3. List the hello-world container (spawned by the image) which exits after displaying its message. If it is still running, you do not need the --all option:

        $ docker ps --all
    
        CONTAINER ID     IMAGE           COMMAND      CREATED            STATUS
        54f4984ed6a8     hello-world     "/hello"     20 seconds ago     Exited (0) 19 seconds ago
    

Conclusion

At this point, you’ve installed Docker Desktop on your development machine, and ran a quick test to ensure you are set up to build and run your first containerized application.

No comments:

Post a Comment

Manage Docker as a non-root user

  The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user   root   and other users ...