github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/docs/tutorials/podman_tutorial.md (about)

     1  ![PODMAN logo](../../logo/podman-logo-source.svg)
     2  
     3  # Basic Setup and Use of Podman
     4  Podman is a utility provided as part of the libpod library.  It can be used to create and maintain
     5  containers. The following tutorial will teach you how to set up Podman and perform some basic
     6  commands with Podman.
     7  
     8  If you are running on a Mac, you should instead follow the [Mac tutorial](https://github.com/containers/libpod/blob/master/docs/tutorials/mac_client.md)
     9  to set up the remote Podman client.
    10  
    11  **NOTE**: the code samples are intended to be run as a non-root user, and use `sudo` where
    12  root escalation is required.
    13  
    14  ## Installing Podman
    15  
    16  For installing or building Podman, please see the [installation instructions](https://github.com/containers/libpod/blob/master/install.md).
    17  
    18  ## Familiarizing yourself with Podman
    19  
    20  ### Running a sample container
    21  This sample container will run a very basic httpd server that serves only its index
    22  page.
    23  ```console
    24  podman run -dt -p 8080:8080/tcp -e HTTPD_VAR_RUN=/var/run/httpd -e HTTPD_MAIN_CONF_D_PATH=/etc/httpd/conf.d \
    25                    -e HTTPD_MAIN_CONF_PATH=/etc/httpd/conf \
    26                    -e HTTPD_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/httpd/ \
    27                    registry.fedoraproject.org/f27/httpd /usr/bin/run-httpd
    28  ```
    29  Because the container is being run in detached mode, represented by the *-d* in the `podman run` command, Podman
    30  will print the container ID after it has run. Note that we use port forwarding to be able to
    31  access the HTTP server. For successful running at least slirp4netns v0.3.0 is needed.
    32  
    33  ### Listing running containers
    34  The Podman *ps* command is used to list creating and running containers.
    35  ```console
    36  podman ps
    37  ```
    38  
    39  Note: If you add *-a* to the *ps* command, Podman will show all containers.
    40  ### Inspecting a running container
    41  You can "inspect" a running container for metadata and details about itself.  We can even use
    42  the inspect subcommand to see what IP address was assigned to the container. As the container is running in rootless mode, an IP address is not assigned and the value will be listed as "none" in the output from inspect.
    43  ```console
    44  $ podman inspect -l | grep IPAddress\":
    45              "SecondaryIPAddresses": null,
    46              "IPAddress": "",
    47  ```
    48  
    49  Note: The -l is a convenience argument for **latest container**.  You can also use the container's ID instead
    50  of -l.
    51  
    52  ### Testing the httpd server
    53  Now that we have the IP address of the container, we can test the network communication between the host
    54  operating system and the container using curl. The following command should display the index page of our
    55  containerized httpd server.
    56  ```console
    57  curl http://<IP_address>:8080
    58  ```
    59  
    60  ### Viewing the container's logs
    61  You can view the container's logs with Podman as well:
    62  ```console
    63  $ sudo podman logs --latest
    64  10.88.0.1 - - [07/Feb/2018:15:22:11 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
    65  10.88.0.1 - - [07/Feb/2018:15:22:30 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
    66  10.88.0.1 - - [07/Feb/2018:15:22:30 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
    67  10.88.0.1 - - [07/Feb/2018:15:22:31 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
    68  10.88.0.1 - - [07/Feb/2018:15:22:31 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
    69  ```
    70  
    71  ### Viewing the container's pids
    72  And you can observe the httpd pid in the container with *top*.
    73  ```console
    74  $ sudo podman top <container_id>
    75    UID   PID  PPID  C STIME TTY          TIME CMD
    76      0 31873 31863  0 09:21 ?        00:00:00 nginx: master process nginx -g daemon off;
    77    101 31889 31873  0 09:21 ?        00:00:00 nginx: worker process
    78  ```
    79  
    80  ### Checkpointing the container
    81  Checkpointing a container stops the container while writing the state of all processes in the container to disk.
    82  With this a container can later be restored and continue running at exactly the same point in time as the
    83  checkpoint. This capability requires CRIU 3.11 or later installed on the system.
    84  To checkpoint the container use:
    85  ```console
    86  sudo podman container checkpoint <container_id>
    87  ```
    88  
    89  ### Restoring the container
    90  Restoring a container is only possible for a previously checkpointed container. The restored container will
    91  continue to run at exactly the same point in time it was checkpointed.
    92  To restore the container use:
    93  ```console
    94  sudo podman container restore <container_id>
    95  ```
    96  
    97  After being restored, the container will answer requests again as it did before checkpointing.
    98  ```console
    99  curl http://<IP_address>:8080
   100  ```
   101  
   102  ### Migrate the container
   103  To live migrate a container from one host to another the container is checkpointed on the source
   104  system of the migration, transferred to the destination system and then restored on the destination
   105  system. When transferring the checkpoint, it is possible to specify an output-file.
   106  
   107  On the source system:
   108  ```console
   109  sudo podman container checkpoint <container_id> -e /tmp/checkpoint.tar.gz
   110  scp /tmp/checkpoint.tar.gz <destination_system>:/tmp
   111  ```
   112  
   113  On the destination system:
   114  ```console
   115  sudo podman container restore -i /tmp/checkpoint.tar.gz
   116  ```
   117  
   118  After being restored, the container will answer requests again as it did before checkpointing. This
   119  time the container will continue to run on the destination system.
   120  ```console
   121  curl http://<IP_address>:8080
   122  ```
   123  
   124  ### Stopping the container
   125  To stop the httpd container:
   126  ```console
   127  sudo podman stop --latest
   128  ```
   129  You can also check the status of one or more containers using the *ps* subcommand. In this case, we should
   130  use the *-a* argument to list all containers.
   131  ```console
   132  sudo podman ps -a
   133  ```
   134  
   135  ### Removing the container
   136  To remove the httpd container:
   137  ```console
   138  sudo podman rm --latest
   139  ```
   140  You can verify the deletion of the container by running *podman ps -a*.
   141  
   142  ## Integration Tests
   143  For more information on how to setup and run the integration tests in your environment, checkout the Integration Tests [README.md](../../test/README.md)
   144  
   145  ## More information
   146  
   147  For more information on Podman and its subcommands, checkout the asciiart demos on the [README.md](../../README.md#commands)
   148  page.