---
title: snapshot_socket
sidebar_position: 0
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

The `snapshot_socket` shows existing sockets.

## Requirements

- Minimum Kernel Version : 5.8

## Getting started

Running the gadget:

<Tabs groupId="env">
    <TabItem value="kubectl-gadget" label="kubectl gadget">
        ```bash
        $ kubectl gadget run ghcr.io/inspektor-gadget/gadget/snapshot_socket:%IG_TAG% [flags]
        ```
    </TabItem>

    <TabItem value="ig" label="ig">
        ```bash
        $ sudo ig run ghcr.io/inspektor-gadget/gadget/snapshot_socket:%IG_TAG% [flags]
        ```
    </TabItem>
</Tabs>

## Guide

Run a pod / container:

<Tabs groupId="env">
<TabItem value="kubectl-gadget" label="kubectl gadget">
```bash
$ kubectl run --restart=Never --image=nginx test-snapshot-socket
pod/test-snapshot-socket created
```
</TabItem>

<TabItem value="ig" label="ig">
```bash
$ docker run --name test-snapshot-socket -d nginx
...
```
</TabItem>
</Tabs>

Then, run the gadget and see how it shows the sockets used by nginx:

<Tabs groupId="env">
<TabItem value="kubectl-gadget" label="kubectl gadget">
```bash
$ kubectl gadget run snapshot_socket:%IG_TAG%
K8S.NODE            K8S.NAMESPACE         K8S.PODNAME           K8S.CONTAINERNAME     SRC                        DST                        STATE
minikube-docker     default               test-snapshot-socket  test-snapshot-socket  :::80                      :::0                       10
minikube-docker     default               test-snapshot-socket  test-snapshot-socket  0.0.0.0:80                 0.0.0.0:0                  10
^C
```

</TabItem>

<TabItem value="ig" label="ig">
```bash
$ sudo ig run snapshot_socket:%IG_TAG% -c test-snapshot-socket
RUNTIME.CONTAINERNAME              SRC                                           DST                                          STATE
test-snapshot-socket               :::80                                         :::0                                         10
test-snapshot-socket               0.0.0.0:80                                    0.0.0.0:0                                    10
^C
```
</TabItem>
</Tabs>

Finally, clean the system:

<Tabs groupId="env">
<TabItem value="kubectl-gadget" label="kubectl gadget">
```bash
$ kubectl delete pod test-snapshot-socket
```
</TabItem>

<TabItem value="ig" label="ig">
```bash
$ docker rm -f test-snapshot-socket
```
</TabItem>
</Tabs>
