github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/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 or Windows PC, you should instead follow the [Mac and Windows tutorial](https://github.com/containers/podman/blob/master/docs/tutorials/mac_win_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/podman/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/f29/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  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  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  This feature is not supported as rootless; as such, if you wish to try it, you'll need to re-create your container as root, using the same command but with sudo.
    85  
    86  To checkpoint the container use:
    87  ```console
    88  sudo podman container checkpoint <container_id>
    89  ```
    90  
    91  ### Restoring the container
    92  Restoring a container is only possible for a previously checkpointed container. The restored container will
    93  continue to run at exactly the same point in time it was checkpointed.
    94  To restore the container use:
    95  ```console
    96  sudo podman container restore <container_id>
    97  ```
    98  
    99  After being restored, the container will answer requests again as it did before checkpointing.
   100  ```console
   101  curl http://<IP_address>:8080
   102  ```
   103  
   104  ### Migrate the container
   105  To live migrate a container from one host to another the container is checkpointed on the source
   106  system of the migration, transferred to the destination system and then restored on the destination
   107  system. When transferring the checkpoint, it is possible to specify an output-file.
   108  
   109  On the source system:
   110  ```console
   111  sudo podman container checkpoint <container_id> -e /tmp/checkpoint.tar.gz
   112  scp /tmp/checkpoint.tar.gz <destination_system>:/tmp
   113  ```
   114  
   115  On the destination system:
   116  ```console
   117  sudo podman container restore -i /tmp/checkpoint.tar.gz
   118  ```
   119  
   120  After being restored, the container will answer requests again as it did before checkpointing. This
   121  time the container will continue to run on the destination system.
   122  ```console
   123  curl http://<IP_address>:8080
   124  ```
   125  
   126  ### Stopping the container
   127  To stop the httpd container:
   128  ```console
   129  podman stop --latest
   130  ```
   131  You can also check the status of one or more containers using the *ps* subcommand. In this case, we should
   132  use the *-a* argument to list all containers.
   133  ```console
   134  podman ps -a
   135  ```
   136  
   137  ### Removing the container
   138  To remove the httpd container:
   139  ```console
   140  podman rm --latest
   141  ```
   142  You can verify the deletion of the container by running *podman ps -a*.
   143  
   144  ## Integration Tests
   145  For more information on how to setup and run the integration tests in your environment, checkout the Integration Tests [README.md](../../test/README.md)
   146  
   147  ## More information
   148  
   149  For more information on Podman and its subcommands, checkout the asciiart demos on the [README.md](../../README.md#commands)
   150  page.