Cloud Native 11 min read

Master Docker Containers: Create, Run, Manage, and Migrate with Ease

This comprehensive guide walks you through Docker container fundamentals, covering creation, starting, stopping, executing commands inside, removal, import/export for migration, inspection, real‑time monitoring, and file copying between host and container, all with clear examples and command syntax.

Open Source Linux
Open Source Linux
Open Source Linux
Master Docker Containers: Create, Run, Manage, and Migrate with Ease

Introduction

After learning about images, it's time to work with containers. A container is a running instance of an image, similar to launching a VM from a template.

This chapter covers important container operations, including docker create , docker start , docker stop , docker exec , docker rm , container migration via import/export, and data copying between container and host.

1. Create a Container

1.1 New container

Syntax:

docker create -it ubuntu:18.04

Parameters: -i Keep STDIN open for interactive use. -t Allocate a pseudo‑TTY.

1.2 Start a Container

Containers created with docker create are in a stopped state; start them with docker start .
docker start eeb

Verify with docker ps.

1.3 Create and Run

Use docker run to create and start in one step.

docker run -it ubuntu /bin/bash
docker run combines docker create and docker start .

1.4 Run in Background

Add -d to run detached. Alternatively, press Ctrl+P+Q to detach without stopping.

2. Stop a Container

2.1 Pause

Pause all processes: docker pause <container_id> Resume with docker unpause.

2.2 Stop

Send SIGTERM then SIGKILL after timeout.

docker stop 021

2.3 Kill

Force termination with SIGKILL.

docker kill 021

2.4 Remove Stopped Containers

docker container prune

3. Enter a Container

Use docker exec -it <container_id> /bin/bash to get a shell.

docker exec -it 021 /bin/bash

4. Delete a Container

Remove stopped containers with docker rm; add -f to force removal of running containers.

docker rm <container_id>
docker rm -f <container_id>

5. Import and Export

5.1 Export

Export a container to a tar file.

docker export 79b > /data/myubuntu.tar

5.2 Import

Import the tar file as a new image.

docker import /data/myubuntu.tar qinlulu/ubuntu:v1

6. Inspect Containers

Show detailed JSON info:

docker inspect <container_id>

7. List Processes

Similar to Linux top:

docker top <container_id>

8. Real‑time Stats

Monitor CPU, memory, network, etc.

docker stats <container_id>

9. Copy Files

Copy from host to container: docker cp /data dba277:/test123 Copy from container to host:

docker cp dba277:/test123 /tmp

Command Summary

docker create -it ubuntu:18.04
docker start <container_id>
docker run -it ubuntu /bin/bash
docker pause <container_id>
docker unpause <container_id>
docker stop <container_id>
docker kill <container_id>
docker exec -it <container_id> /bin/bash
docker rm <container_id>
docker rm -f <container_id>
docker export 79b > myubuntu.tar
docker import myubuntu.tar qinlulu/ubuntu:v1
docker inspect <container_id>
docker top <container_id>
docker stats <container_id>
docker cp /data dba277:/test123
docker cp dba277:/test123 /tmp
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpsContainer ManagementDocker Commands
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.